Skip to content

test(rails): isolate app-booting specs in forked processes - #3239

Open
solnic wants to merge 2 commits into
ci/cache-gem-downloadsfrom
test/rails-fork-isolation
Open

solnic wants to merge 2 commits into
ci/cache-gem-downloadsfrom
test/rails-fork-isolation

Conversation

@solnic

@solnic solnic commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Every sentry-rails spec boots a fresh Rails app in the same process. Boot-time global state (load hooks, ActiveJob callbacks, singletons) piles up, which makes specs flaky and slower over the run.

Instead of resetting Rails internals, specs that boot an app now run in a forked child, so that state dies with the child:

  • isolate: true runs each example in its own fork.
  • isolate: :group runs each top-level group in one fork. The ActiveJob specs use it because they boot once in before(:all).
  • The parent records each child's result (failures, skips, crashes, 120s timeout) on the real examples, so formatters and the exit status work as usual.
  • Coverage from the children is merged back.
  • Where fork isn't available (JRuby), tagged specs run in-process, as today.

On top of #3245 and #3247, the full run finishes in 8.6 min instead of about 12–15 min. The Rails 8.x cells drop from 417–599s to about 209s.

@solnic
solnic marked this pull request as ready for review November 24, 2026 18:26
@solnic
solnic requested a review from a team as a code owner November 24, 2026 18:26

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9f206f8. Configure here.

Comment thread sentry-rails/spec/isolation_spec.rb Resolved
ensure
reader&.close
writer&.close
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forked specs reuse parent DB connections

Medium Severity

Isolated examples are forked after the suite has already opened ActiveRecord’s SQLite connection, and the child never reconnects. SQLite (and the copied pool) is not safe to use across fork, so app-booting specs that query in the child can see locks, SQLITE_MISUSE, or stale pool stats.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 9f206f8. Configure here.

@solnic
solnic force-pushed the test/rails-fork-isolation branch from 9f206f8 to 87d0926 Compare November 25, 2026 09:53
@solnic
solnic changed the base branch from master to ci/optimize-source-built-rubies November 25, 2026 11:55
@solnic
solnic force-pushed the test/rails-fork-isolation branch from 68f76c2 to 4cd6fb1 Compare November 25, 2026 11:56
@solnic
solnic added this pull request to stack #3246 November 25, 2026 11:56
Comment thread sentry-rails/spec/support/isolation.rb Resolved
@solnic
solnic force-pushed the test/rails-fork-isolation branch from 4cd6fb1 to 480913e Compare November 25, 2026 12:25
@solnic
solnic removed this pull request from stack #3246 November 25, 2026 12:33
@solnic
solnic changed the base branch from ci/optimize-source-built-rubies to ci/cache-gem-downloads November 25, 2026 12:33
@solnic
solnic added this pull request to stack #3248 November 25, 2026 12:33
@solnic
solnic force-pushed the test/rails-fork-isolation branch from 480913e to ff246d5 Compare November 25, 2026 13:40
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