Skip to content

Keep semaphore slots held while blocked jobs are enqueued in concurrency test - #776

Merged
rosa merged 1 commit into
rails:mainfrom
wintan1418:widen-concurrency-test-margins
Aug 18, 2026
Merged

Keep semaphore slots held while blocked jobs are enqueued in concurrency test#776
rosa merged 1 commit into
rails:mainfrom
wintan1418:widen-concurrency-test-margins

Conversation

@wintan1418

Copy link
Copy Markdown
Contributor

Related to #602

Problem

ConcurrencyControlsTest#test_run_several_jobs_over_the_same_record_limiting_concurrency is one of the most frequent CI flakes at the moment — it failed standalone on recent main runs (e.g. the run for 7f59932) and on unrelated PR runs, always on the same assertion:

Expected: 5
  Actual: 4  # BlockedExecution difference

The test claims all three semaphore slots with jobs A, B and C, waits until the three are claimed, then enqueues D–H expecting all five to become BlockedExecution. A and B only pause for 0.5s — and that clock starts as soon as they're claimed, before the wait even returns. On a slow runner, by the time the five D–H perform_later inserts complete, A or B has already finished and released a semaphore slot, so one of D–H claims it instead of blocking, and the +5 assertion comes up short.

Fix

Give A and B enough pause (1.5s) to still be holding their slots while D–H are being enqueued, and bump C (3s → 4s) so it keeps finishing well after everything else, preserving the test's final ["C"] assertion. The constraint is now also documented in the test comment.

Adds ~1s to the test's runtime in exchange for tripling the margin on the race window.

Testing

Ran the test 6 consecutive times on MySQL plus the full concurrency_controls_test.rb file — all green.

…ncy test

"run several jobs over the same record limiting concurrency" claims all
three semaphore slots with jobs A, B and C, then enqueues D-H expecting
all five to block. A and B only paused for 0.5 seconds, so on a slow CI
runner they could finish while D-H were still being inserted, freeing a
slot that let some of them run instead of blocking and failing the +5
BlockedExecution assertion.

Give A and B enough pause to outlive the enqueue window, and bump C
accordingly so it still saves last.

Related to rails#602

@rosa rosa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @wintan1418! These tests are quite flaky and tricky to get right... I might rewrite all of them at some point 😅

@rosa
rosa merged commit a0fc4de into rails:main Aug 18, 2026
56 of 58 checks passed
@wintan1418

wintan1418 commented Aug 18, 2026 via email

Copy link
Copy Markdown
Contributor Author

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.

2 participants