News for hackers. Stuff that matters.
Re:Why We’re Sticking with Ruby on Rails at Gitlab by worker_person on Monday June 13, 2022 @12:59PM (#31728230)
When you hit scale. Rails is not the concern. It's the datastore.

All of the major performance problems at scale I've dealt with came down to a super giant table that keeps getting locked.

Re:Why We’re Sticking with Ruby on Rails at Gitlab by itake on Monday June 13, 2022 @01:11PM (#31728424)
In another comment, it said Gitlab moved off ActiveRecord.

The fundamental problem with rspec + ActiveRecord is for each test: you create db state (tons of inserts), run the test (more db reads and writes), and then tear down the state. This is very expensive when you have 100,000s of tests each taking 500ms.

Rails/rspec does not make it easy to stub db state with ActiveRecord.

Re:Why We’re Sticking with Ruby on Rails at Gitlab by worker_person on Monday June 13, 2022 @01:29PM (#31728647)
http://underpop.online.fr/r/ruby/rails/tutorial/ruby-on-rail...

Use transactional fixtures as much as possible. Minimal db usage between tests.

Re:Why We’re Sticking with Ruby on Rails at Gitlab by itake on Monday June 13, 2022 @01:39PM (#31728764)
yes, that improves clean up time, but doesn't help with all of the db writes you have to make to create db state for each test case.
Re:Why We’re Sticking with Ruby on Rails at Gitlab by worker_person on Monday June 13, 2022 @03:02PM (#31730079)
Initial state is loaded via fixtures or whatever. (slow and expensive)

Transaction is started. Run Test 1 Transaction rolled back. (quick)

Test 2 can be run without the expensive fixtures.

Repeat for all tests.

Re:Why We’re Sticking with Ruby on Rails at Gitlab by itake on Monday June 13, 2022 @03:15PM (#31730275)
Does this mean if you only want to run the tests for `users_controller` during development, you still have to load the fixtures for all other tests with each run?
Re:Why We’re Sticking with Ruby on Rails at Gitlab by worker_person on Tuesday June 14, 2022 @01:25PM (#31742833)
In the normal case. When you start a test it loads from fixtures into its own database.

Any test can make use of what is in that database. So you tend to put a bunch of stuff that is useful for most tests.

If a specific test needs an unusual setup, then it can do whatever is needed to load data. Generate data, load extra fixtures, etc. You can do this on a per test basis, or a group of tests, etc.

An option is to reload everything between each test. Not recommended.

Normal usage is to rollback any changes a test did, so that each test has a clean slate. This tends to be plenty fast. Parallelism can usually be done.

If speed is still a concern, you can get fancy and load up multiple databases with fixtures and divide tests between them. Maybe have 2-8 sets of tests running at same time.

It's been a few years, but I've inherited test suites that take 14 hours and been able to get them down to a few minutes with above techniques.

Something like Guard can be setup to automatically run tests relevant to what you're working on. So you don't have to run full suite each time.