Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

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

Adbot
ADBOT LOVES YOU

Sivart13
May 18, 2003
I have neglected to come up with a clever title

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.
There's slow, and there's slow.

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:
ActiveRecord::Base.descendants.each do |sc|
  if (sc.try(:all).try(:size) rescue nil || 0) > 0
    puts "#{sc.name}: #{sc.all.size}"
  end
end

Pollyanna
Mar 5, 2005

Milk's on them.


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?

These seem like some obvious things to speed up your model specs, hard to tell more without additional context. Handful of seconds for a model spec sounds like a lot of time TBH.

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 :gonk:

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.

  • See if there's any common setup you can do before the suite instead of before each test
  • Are you writing/reading from the database when you don't actually need to? Validation tests, for example, don't always need to persist the model to test.
  • Do you have a lot of before/after hooks in your models? If you do, I'm sorry. You're boned unless you refactor that poo poo out.

I worked at a rails shop a couple years back that had a 20 minute suite but it ran on 15 nodes with 2 runners each. This was mostly because of the 3rd point. Running the whole suite locally took hours.

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

necrotic
Aug 2, 2005
I owe my brother big time for this!
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

Pollyanna
Mar 5, 2005

Milk's on them.


We’re stuck behind 2.1.5 unfortunately (too scared to upgrade), so test-prof won’t work :(

necrotic
Aug 2, 2005
I owe my brother big time for this!
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.

Pollyanna
Mar 5, 2005

Milk's on them.


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.

Tea Bone
Feb 18, 2011

I'm going for gasps.
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?

necrotic
Aug 2, 2005
I owe my brother big time for this!
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.

kayakyakr
Feb 16, 2004

Kayak is true
I agree. Kill all the old migrations, start from where you're at and move forward from there.

Nybble
Jun 28, 2008

praise chuck, raise heck
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 =(

necrotic
Aug 2, 2005
I owe my brother big time for this!
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.

Sivart13
May 18, 2003
I have neglected to come up with a clever title

necrotic posted:

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.
You are correct and you should hold this fact over your co-workers (and I've worked on tons of apps where migrate from zero works)

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

xtal
Jan 9, 2011

by Fluffdaddy
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

manero
Jan 30, 2006

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.

necrotic
Aug 2, 2005
I owe my brother big time for this!

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.

xtal
Jan 9, 2011

by Fluffdaddy
Also, if you are distributing your app, you need to preserve all migrations (they are essentially part of your public API.)

necrotic
Aug 2, 2005
I owe my brother big time for this!

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.

KoRMaK
Jul 31, 2012



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.

necrotic
Aug 2, 2005
I owe my brother big time for this!
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

KoRMaK
Jul 31, 2012



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

necrotic
Aug 2, 2005
I owe my brother big time for this!
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.

KoRMaK
Jul 31, 2012



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

AWS competitor to the app service (beanstalk) let you configure custom commands but I don't see an option for that in Azure.

Dang thats what I was afraid of. Thanks

I might have to start doing docker stuff sooner than I thought.

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Just switch to serverless everyone’s doing it

KoRMaK
Jul 31, 2012



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.
2018-08-03T18:58:41.538542589Z Bundle install with options --without development,test
2018-08-03T18:58:41.538688289Z Defaulting gem installation directory to /tmp/bundle
2018-08-03T18:58:41.538827789Z Defaulting site config directory to /home/site/config
2018-08-03T18:58:41.539147589Z Secret key base present
2018-08-03T18:58:41.539292889Z RAILS_ENV not set, default to production
2018-08-03T18:58:41.539385089Z Removing any leftover pids if present
2018-08-03T18:58:41.557234689Z Running bundle check
2018-08-03T18:58:41.557436989Z /opt/startup.sh: line 67: [: : integer expression expected
2018-08-03T18:58:43.539626561Z You are replacing the current local value of path, which is currently "/home/site/wwwroot/vendor/bundle"
2018-08-03T18:58:46.155892524Z missing dependencies, try redeploying

necrotic
Aug 2, 2005
I owe my brother big time for this!
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

KoRMaK
Jul 31, 2012



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?

necrotic
Aug 2, 2005
I owe my brother big time for this!

KoRMaK posted:

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?

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.

KoRMaK
Jul 31, 2012



necrotic posted:

Switching to the container service and building a fixed image yourself is probably better at this point.
Ugh, yea. Another couple hours instead of couple minutes.

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

KoRMaK
Jul 31, 2012



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

kayakyakr
Feb 16, 2004

Kayak is true
90% of the time, it's better to just deploy to heroku and be done with it.

KoRMaK
Jul 31, 2012



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

Pardot
Jul 25, 2001




I'm hoping to continue my streak of never typing the word docker into a command line for the rest of my life :kiddo:

xtal
Jan 9, 2011

by Fluffdaddy
nm

xtal fucked around with this message at 20:22 on Aug 4, 2018

KoRMaK
Jul 31, 2012



What was the one before this? You made recipes or some poo poo. Not Capistrano....

xtal
Jan 9, 2011

by Fluffdaddy
Chef?

Docker is orthogonal to deployment tho.

KoRMaK
Jul 31, 2012



Maybe it was that or puppet, I thought there was another one that started with an m

kayakyakr
Feb 16, 2004

Kayak is true
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).

KoRMaK
Jul 31, 2012



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.

Adbot
ADBOT LOVES YOU

kayakyakr
Feb 16, 2004

Kayak is true

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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply