just wanna reiterate that you should be mocking pretty much everything except the bits of domain logic the unit test is specifically for. this will make your poo poo way faster
|
|
# ? May 5, 2018 01:41 |
|
|
# ? May 15, 2024 16:54 |
|
xtal posted:This is correct, so you should tackle those low-hanging fruit first if they are applicable. Once the code is perfect, there is still the problem that each and every Rails app eventually has a slow test suite. Teams can still be very productive working on an app with integration tests that take hours to run single-threadedly, as long as they can run the whole suite fast in a parallel environment like CircleCI. Depending on the size of the app, nobody's /models/ folder should take hours to run locally. My wild-rear end guess regarding the stated "3-5 seconds" figure is that every test is blowing away the whole DB and building a shitload of fixture data. For reference, a given test in the app I work on takes ~300ms even though it creates 10+ records. Ideally a model test that touches the database should make as few database records as possible to exhibit the model behavior. Two paradigms I've seen are: * The database starts out empty, and the test makes whatever it needs via factories * The database starts out full of fixture data, and tests run in a transaction so they can bring it back to the normal state between tests My guess is that your app is doing both, starting from zero and adding a ton of predefined "fixture" records that are slow to create. You could try running something like this after the last assertion in a test to see if a lot of stray data is lying around: code:
|
# ? May 5, 2018 01:55 |
|
Gmaz posted:Can you mock dependencies for test scenarios instead of creating them in the DB, can you just build the model itself instead of writing it to the DB? If you need to change column values to prepare for a test do you do it without triggering callbacks? Can you pull logic outside of models into a PORO and then test that PORO? It is a lot of time, yes, and there’s a significant amount of logic in the models. It seems that we rely heavily on validations, callbacks, and before/afters in a cascading fashion in our codebase necrotic posted:Parallel tests will not help a whole lot if he's already spreading it over 8 servers. Your model tests sound more like full on integration tests if they're taking 3-5 seconds each. Yeah, I wouldn’t be surprised if point 3 was the culprit. It’s a bog standard lovely rails app that we want to chop up this year, and it’s pretty crufty. Wondering if it’s more work to try and fix it now than to wait for the chop. Are there useful tools or gems that can profile the amount of time taken during tests, in heavy detail? I’d love to know how much time is setup, how much time is database access, etc. Pollyanna fucked around with this message at 14:37 on May 7, 2018 |
# ? May 7, 2018 14:34 |
|
ruby-prof is the general profiling gem. edit: https://github.com/palkan/test-prof may be better for what you want necrotic fucked around with this message at 14:47 on May 7, 2018 |
# ? May 7, 2018 14:43 |
|
We’re stuck behind 2.1.5 unfortunately (too scared to upgrade), so test-prof won’t work
|
# ? May 7, 2018 16:38 |
|
Ouch. Well, ruby-prof and TracePoint (pretty sure that's available in 2.1) can give you what you need with some work. Ruby-prof has the benefit of creating cachegrind formatted files which tools exist to inspect, like KCacheGrind.
|
# ? May 7, 2018 16:52 |
|
Yeah, the codebase is a bit of a dinosaur. I might just make a 2.2.0 branch and do profiling on my own instead, and deal with the breakages as they come.
|
# ? May 7, 2018 17:06 |
|
I have an old rails application whose database has had a sizeable number of tables/columns added and changed without using migrations. I've decided it's time for a big clean up and to get everything in line. Is there an easy way I can find discrepancies between the existing database and the migrations? I've considered running db:schema:dump and deleting all migration files but I'm not sure if that's a good idea/possible negative repercussions?
|
# ? Jun 6, 2018 14:28 |
|
Doing that is perfectly fine. While it is nice to have the migration artifcats at a certain point they become less a need. In my experiences most code bases can't even migrate from zero after a long existence, and you're clearly in that scenario.
|
# ? Jun 6, 2018 14:40 |
|
I agree. Kill all the old migrations, start from where you're at and move forward from there.
|
# ? Jun 6, 2018 21:27 |
|
db:schema:dump and comparing the diff with the existing migration-created schema.rb might be interesting to see what is different. That said, I agree with the others; sometimes you just have to flatten the Migration history and start again from a good spot. And I may even be in favor of flattening often, but I haven't worked on a Rails codebase that actually used Migrations in a while =(
|
# ? Jun 6, 2018 21:51 |
|
I'm in favor of flattening after some time period but everyone I've worked with is against it. I've never worked on a code bases where migrate from zero works.
|
# ? Jun 7, 2018 00:05 |
|
necrotic posted:I'm in favor of flattening after some time period but everyone I've worked with is against it. Migrations only need to live until they've run on most extant system with data (staging, production, developer machines), after that they only exist to gunk up your IDE's search index. Toast 'em. The only reason you MIGHT want to keep them around longer is if your app was deployed on a lot of systems you didn't control, like on-premise in many client's own infrastructure. Then you might have to support an upgrade path from tons of prior versions. Otherwise, if you really needed to run a very old migration you can find them in git. Sivart13 fucked around with this message at 03:51 on Jun 7, 2018 |
# ? Jun 7, 2018 02:38 |
|
When you say "it's okay to delete migrations" I'll say "as long as you keep them in git history." You definitely want to be able to regenerate your schema from migrations at any time. The canon schema is the sum of your migrations, and that is a good way to enforce that
|
# ? Jun 9, 2018 19:56 |
|
xtal posted:When you say "it's okay to delete migrations" I'll say "as long as you keep them in git history." You definitely want to be able to regenerate your schema from migrations at any time. The canon schema is the sum of your migrations, and that is a good way to enforce that I'd also like to add, this is why you should also be checking in your schema.rb file. You can remove old migrations, but then when you're setting up the project you can do "rake db:schema:load" or "rake db:setup" and it will load from schema.rb. The schema.rb is your canonical source of knowledge, and the migrations are how you got there.
|
# ? Jun 9, 2018 20:03 |
|
manero posted:I'd also like to add, this is why you should also be checking in your schema.rb file. You can remove old migrations, but then when you're setting up the project you can do "rake db:schema:load" or "rake db:setup" and it will load from schema.rb. The schema.rb is your canonical source of knowledge, and the migrations are how you got there. Yeah this. If you need to rebuild your schema.rb from migrations you done hosed up. Obviously keep them in git history, don't go arbitration deleting files and rewriting the git log.
|
# ? Jun 10, 2018 17:14 |
|
Also, if you are distributing your app, you need to preserve all migrations (they are essentially part of your public API.)
|
# ? Jun 10, 2018 18:56 |
|
xtal posted:Also, if you are distributing your app, you need to preserve all migrations (they are essentially part of your public API.) What? The schema.rb is that, the migrations are how you got there. edit: Oh, you mean for upgrades. Yeah you need them for that, but you could also only support certain upgrade paths to limit this somewhat.
|
# ? Jun 10, 2018 22:45 |
|
I'm trying to deploy my rails app to Azure, using the linux ruby 2.3.3 image. My app won't come up though, and my current issue is that it's not running bundle install on deployment. It did run it a few times, but I have no idea how I triggered it. Does anyone have azure experience that can tell me how to get the bundle install running when I push to azure? I also can't ssh into the server, I can only kudu with a bash which doesn't let me run the commands I normally would. Azure is bad I hate it.
|
# ? Aug 3, 2018 16:15 |
|
It should always run it on start. Here's the script that handles everything in their image: https://github.com/Azure-App-Service/ruby/blob/master/2.3.3/startup.sh
|
# ? Aug 3, 2018 16:27 |
|
necrotic posted:It should always run it on start. Here's the script that handles everything in their image: https://github.com/Azure-App-Service/ruby/blob/master/2.3.3/startup.sh Oh snap thats rad, thank you. Can I alter this script or add my own deployment script in their provided ruby images? It's just killing me that I can't ssh directly into it and run the commands myself. It doesn't let me connect and I think its a firewall issue but I haven't even set up the firewall yet so it must be default thing with azure? KoRMaK fucked around with this message at 16:56 on Aug 3, 2018 |
# ? Aug 3, 2018 16:54 |
|
App Services like that almost never give you direct SSH access. If you wanted to run your own container (such as a customized version of that image) you'd need to use their container service https://azuremarketplace.microsoft.com/en-us/marketplace/apps/microsoft.acs AWS competitor to the app service (beanstalk) let you configure custom commands but I don't see an option for that in Azure.
|
# ? Aug 3, 2018 16:59 |
|
necrotic posted:App Services like that almost never give you direct SSH access. If you wanted to run your own container (such as a customized version of that image) you'd need to use their container service https://azuremarketplace.microsoft.com/en-us/marketplace/apps/microsoft.acs Dang thats what I was afraid of. Thanks I might have to start doing docker stuff sooner than I thought.
|
# ? Aug 3, 2018 19:18 |
Just switch to serverless everyone’s doing it
|
|
# ? Aug 3, 2018 19:29 |
|
My docker logs are saying this "/opt/startup.sh: line 67: [: : integer expression expected" and I traced the output with the startup.sh file and I'm pretty sure it's saying the right line Which is this line I think https://github.com/Azure-App-Service/ruby/blob/master/2.3.3/startup.sh#L67 Wtf though I can't edit that file why is it blowing up quote:2018-08-03T18:58:40.884758298Z Starting OpenBSD Secure Shell server: sshd.
|
# ? Aug 3, 2018 20:08 |
|
Wow. Yeah they don't have a default value for ZIPPED_GESM so if you don't have a gems.tgz file the shell script is invalid: [ "" -eq 1 ] won't work! https://github.com/Azure-App-Service/ruby/pull/11/files
|
# ? Aug 3, 2018 20:10 |
|
Mind bending. This script was last updated last year. Has no one on azure used this service offering and run into this???? So I need to bundle --path my/path, then tgz that and upload it?
|
# ? Aug 3, 2018 20:20 |
|
KoRMaK posted:Mind bending. This script was last updated last year. Has no one on azure used this service offering and run into this???? Seems like nobody is using it, if its been there and broken that long. I dunno what you need to do but that sounds correct? Any binary gems need to be built on the same architecture (presumably linux x86_64). Switching to the container service and building a fixed image yourself is probably better at this point.
|
# ? Aug 3, 2018 20:23 |
|
necrotic posted:Switching to the container service and building a fixed image yourself is probably better at this point. So, a work around I found was to add ZIPPED_GEMS as an appsetting env variable t 0, and it worked! But then I realized the bundle install command isn't until after the check anyway, I don't see how the check could ever pass! https://github.com/chmald/azure-linux-ruby/blob/master/startup.sh#L93 I still don't understand how I saw it install at all yesterday, so wierd
|
# ? Aug 3, 2018 20:30 |
|
I hadn't given up on this quite yet and tried to tgz and upload the gems, I futzed around with the bundle directory and yada yada yada it didn't work It was loving useless. Their script is really broken. The product doesn't work. Don't do what I did. Now I'm off to learn docker poo poo KoRMaK fucked around with this message at 22:43 on Aug 3, 2018 |
# ? Aug 3, 2018 22:37 |
|
90% of the time, it's better to just deploy to heroku and be done with it.
|
# ? Aug 3, 2018 23:20 |
|
I need to learn docker anyway for "career reasons", same with being able to deploy on the two big ☁️ services. So whatever, might as well get into now
|
# ? Aug 4, 2018 01:05 |
|
I'm hoping to continue my streak of never typing the word docker into a command line for the rest of my life
|
# ? Aug 4, 2018 01:22 |
|
nm
xtal fucked around with this message at 20:22 on Aug 4, 2018 |
# ? Aug 4, 2018 01:35 |
|
What was the one before this? You made recipes or some poo poo. Not Capistrano....
|
# ? Aug 4, 2018 01:42 |
|
Chef? Docker is orthogonal to deployment tho.
|
# ? Aug 4, 2018 01:44 |
|
Maybe it was that or puppet, I thought there was another one that started with an m
|
# ? Aug 4, 2018 01:55 |
|
Docker is fine for some things. We've done some cool things with a docker selenium deploy that runs integration tests in a server agnostic way. Docker is also the best way to install service dependencies like databases and redis and EM for your development environment, especially if you're using WSL like me. Kitematic is a great management tool for that use case. Deploying rails is not one of the things that docker does well. It's not worth using for deploys until you have full time devops. And that's not worth doing until you have a heroku bill in the $10k/month range ($120k/year where the devops has room to save you enough cashmoney to justify his cost).
|
# ? Aug 4, 2018 19:32 |
|
We use it at work and we are waaay below that. IT helped us standarize our deployment and app across regions and adhere to regional regulation rules, like in the UAE, EU, etc.
|
# ? Aug 5, 2018 00:17 |
|
|
# ? May 15, 2024 16:54 |
|
KoRMaK posted:We use it at work and we are waaay below that. IT helped us standarize our deployment and app across regions and adhere to regional regulation rules, like in the UAE, EU, etc. Sounds like you either have someone dedicated to full devops, or you are losing money on it. Mind, my business is in early stage startups, so I'm a big fan of path of least resistance.
|
# ? Aug 5, 2018 18:27 |