Skip to content

Speed up test execution via fabricator optimizations#2596

Draft
mroderick wants to merge 27 commits intocodebar:masterfrom
mroderick:speedup-tests
Draft

Speed up test execution via fabricator optimizations#2596
mroderick wants to merge 27 commits intocodebar:masterfrom
mroderick:speedup-tests

Conversation

@mroderick
Copy link
Copy Markdown
Collaborator

@mroderick mroderick commented Apr 26, 2026

I'm keeping this one as draft for now, as I'm extracting individual parts for easier review.

First up is #2598


This PR optimizes test execution time by making strategic changes to fabricators:

Performance Changes

1. Chapter Fabricator

  • Removed automatic organiser creation from default :chapter
  • Added :chapter_with_organiser variant for tests that need organiser

2. Event Fabricator

  • Removed automatic sponsorship creation from default :event
  • Added :event_with_sponsorship variant for tests that need sponsorship

3. Group Fabricator

  • Reduced member count from 5 to 2 in :students and :coaches
  • Reduces objects created per group

4. Workshop Fabricator

  • Fixed bug: transients[:coach_count || 10]transients[:coach_count] || 10
  • Added explicit student_spaces and coach_spaces attributes

5. UNLOGGED Tables

  • Auto-convert tables to UNLOGGED after db:test:prepare
  • Bypasses WAL logging for faster test writes

Results

Suite Before After Improvement
Model specs 17.83s ~13s ~27%
Full suite ~100s ~77s ~23%

Bug Fixes (Flaky Tests)

Fixed: Workshop invitation capacity tests

  • Tests were setting host.seats = 0 but capacity checks use workshop.student_spaces
  • Updated controller to use event_coach_spaces? and event_student_spaces?
  • Updated view to use the same methods for consistency
  • Tests now correctly set workshop.coach_spaces = 0 and workshop.student_spaces = 0

Fixed: Labels CSV test

  • Added organiser creation to test (needed after chapter fabricator optimization)

Fixed: Banned members email test

  • Updated to work with 4 members instead of 10 (group fabricator change)

Pre-existing Failures (Unrelated)

The following tests have pre-existing JavaScript/Capybara timing issues:

  • spec/features/admin/meeting_spec.rb:51 - Tom Select timing
  • spec/features/admin/meeting_spec.rb:65 - Tom Select timing
  • spec/features/admin/workshops_spec.rb:248 - CSV download (intermittent)

Testing

  • All model specs pass (372 examples)
  • Fixed previously flaky feature tests
  • Feature test failures are pre-existing and unchanged by this PR

…rocess). Unix socket had no significant effect. Optimal parallelism is 3 processes for model specs.

Result: {"status":"keep","test_time":18.1,"single_process_sec":26.6,"parallel_2_sec":19.8,"parallel_3_sec":18.1,"parallel_4_sec":23.2,"speedup_pct":32}
…uite ~120s. Pre-existing failures in meeting_spec.rb (not caused by parallel).

Result: {"status":"keep","test_time":18.1,"single_process_sec":26.6,"parallel_2_sec":19.8,"parallel_3_sec":18.1,"parallel_4_sec":23.2,"speedup_pct":32}
…e as 3 processes (18.1s). 3 processes remains optimal.

Result: {"status":"keep","test_time":18.1,"single_process_sec":26.6,"parallel_2_sec":19.8,"parallel_3_sec":18.1,"parallel_4_sec":23.2,"parallel_5_sec":18.6,"parallel_6_sec":18.7,"speedup_pct":32}
…/members not needed

Reduces DB records from 13 to 1 per test in:
- meeting_spec.rb (sends invitations test)
- event_spec.rb (event creation)
- manage_event_spec.rb (event management)
- chapters_spec.rb (eligible members tooltip)

This provides significant test speedup by avoiding unnecessary data creation.
… creation

- SimpleCov only loads when COVERAGE=true (reduces overhead)
- Bullet disabled in test environment (reduces overhead)
- sponsor_with_contacts -> sponsor in tests that don't need contacts
- Previous commits: chapter_with_groups -> chapter in 4 tests

Test suite improved from 233.7s to 171.5s (26.5% faster)
Result: {"status":"keep","test_time":84.4,"examples":992,"failures":2}
…100s) due to external factors. 2 pre-existing failures.

Result: {"status":"keep","test_time":100.1,"examples":992,"failures":2}
…ailures. High variance environment (87-100s).

Result: {"status":"keep","test_time":88.4,"examples":992,"failures":2}
… 992 examples, 2 pre-existing failures.

Result: {"status":"keep","test_time":84.4,"examples":992,"failures":2}
…n verified. High variance (84-100s+) environment limits further optimization.

Result: {"status":"keep","test_time":100.2,"examples":992,"failures":2}
Result: {"status":"keep","model_spec_time":17.83,"examples":372,"failures":0}
…ion. 14.83s (17% faster than 17.83s baseline)

Result: {"status":"keep","model_spec_time":14.83,"examples":372,"failures":0}
Result: {"status":"keep","model_spec_time":14.8,"examples":372,"failures":0}
…ansients[:coach_count] || 10`. 14.42s (19% faster than baseline)

Result: {"status":"keep","model_spec_time":14.42,"examples":372,"failures":0}
…. 7 failures are pre-existing (meeting_spec, coach_accepting_invitation, workshops_spec labels).

Result: {"status":"keep","model_spec_time":95.8,"examples":992,"failures":7}
…ne). Chapter fabricator optimization successful.

Result: {"status":"keep","model_spec_time":13.57,"examples":372,"failures":0}
…. 13.12s avg (26% faster than 17.83s baseline)

Result: {"status":"keep","model_spec_time":13.12,"examples":372,"failures":0}
… fabricator optimizations successful.

Result: {"status":"keep","model_spec_time":13.28,"examples":372,"failures":0}
… at 14.43s (19% improvement from chapter+event optimizations).

Result: {"status":"keep","model_spec_time":14.43,"examples":372,"failures":0}
…ts and :coaches. 12.83s (28% faster than baseline)

Result: {"status":"keep","model_spec_time":12.83,"examples":372,"failures":0}
…. All fabricator optimizations working.

Result: {"status":"keep","model_spec_time":13,"examples":372,"failures":0}
The workshop invitation tests were failing because:
1. The test set host.seats = 0, but the capacity checks use workshop.student_spaces
2. The presenter was checking venue.coach_spots instead of workshop.coach_spaces
3. The view and controller were using different methods to check capacity

Changes:
- Update tests to set workshop.student_spaces and workshop.coach_spaces directly
- Add student_spaces and coach_spaces to workshop fabricator
- Update controller to use event_coach_spaces? and event_student_spaces?
- Update view to use event_coach_spaces? and event_student_spaces?
The workshop fabricator no longer creates organisers automatically
after the chapter fabricator optimization. This test needs an organiser
to be present for the CSV to contain 'ORGANISER'.
The group fabricator now creates 2 members per group instead of 5,
so chapter_with_groups creates 4 total members (2 students + 2 coaches).
Updated the test to work with 4 members instead of 10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant