Repository navigation
Fix flaky bundle version lock concurrency tests - #72572
Merged
Merged
Conversation
The bundle version lock concurrency tests assumed a worker thread had already acquired the lock after a fixed 0.1s sleep. That assumption only holds on an idle machine: under CI-like contention the thread can take longer than that just to be scheduled, so the tests failed for reasons unrelated to the code under test. A failure was also worse than it needed to be. The lock object was assigned inside the worker thread, so a test that ran too early raised AttributeError instead of pointing at the timing; and the stop flag was only set on the success path while join() had no timeout, so a failed assertion left the worker looping forever and hung the job instead of failing it.
ColtenOuO
force-pushed
the
fix-flaky-bundle-lock-tests
branch
from
September 5, 2026 19:16
1dc630f to
b6e08dd
Compare
potiuk
approved these changes
Sep 9, 2026
1 task done
potiuk
added a commit
that referenced
this pull request
Sep 12, 2026
The bundle version lock concurrency tests assumed a worker thread had already acquired the lock after a fixed 0.1s sleep. That assumption only holds on an idle machine: under CI-like contention the thread can take longer than that just to be scheduled, so the tests failed for reasons unrelated to the code under test. A failure was also worse than it needed to be. The lock object was assigned inside the worker thread, so a test that ran too early raised AttributeError instead of pointing at the timing; and the stop flag was only set on the success path while join() had no timeout, so a failed assertion left the worker looping forever and hung the job instead of failing it. (cherry picked from commit dadef4e) Co-authored-by: Jyun-An Chen <[email protected]>
regarmukesh3g
pushed a commit
to regarmukesh3g/airflow
that referenced
this pull request
Sep 27, 2026
The bundle version lock concurrency tests assumed a worker thread had already acquired the lock after a fixed 0.1s sleep. That assumption only holds on an idle machine: under CI-like contention the thread can take longer than that just to be scheduled, so the tests failed for reasons unrelated to the code under test. A failure was also worse than it needed to be. The lock object was assigned inside the worker thread, so a test that ran too early raised AttributeError instead of pointing at the timing; and the stop flag was only set on the success path while join() had no timeout, so a failed assertion left the worker looping forever and hung the job instead of failing it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sumarry
TestBundleVersionLock::test_that_shared_lock_doesnt_block_shared_lockandTestBundleVersionLock::test_that_shared_lock_blocks_ex_lockstarted a worker thread, slept a fixed0.1s, and then asserted that the thread had already entered theBundleVersionLockcontext. That assumption only holds when the machine running the tests is idle. On a loaded CI worker the thread can take longer than0.1sjust to get scheduled and open/flock the lock file, and the test fails for reasons that have nothing to do with the code under test.I measured this inside Breeze on an 8-core box by instrumenting the same helper the tests use and recording the delay between
Thread.start()and the lock actually being held, over 200 iterations:So under CI-like contention the fixed sleep is genuinely too short, at roughly a 0.5% failure rate per assertion on this hardware -- and CI runners are typically smaller and noisier than this one.
Running the two tests themselves in a loop under the same contention reproduces it directly. On
main, 40 iterations produced a real failure (assert lth2.did_lock is True->AssertionError), and after that failure both worker threads kept logging theirsleeping: idx=...lines forever becausestopwas never set, which left the process unable to exit — exactly the hang described below rather than a clean test failure. With this change, 150 iterations (300 test executions) under identical load passed with zero failures and the whole loop finished in 23 seconds.There were two further problems in the same tests, both of which turn a timing miss into a bad failure rather than a clear one:
self.lockerwas only a bare annotation onLockTestHelperand was assigned inside the worker thread. If the thread had not run yet,lth1.locker.lock_file_pathraisedAttributeError, which gives no hint that the real cause is timing.join()with no timeout, and thestopflag was only set on the success path. If an assertion failed beforestopwas set, the worker thread stayed in itswhile not self.stoploop forever and the test hung until the CI job timed out instead of failing fast.Change
did_lockthrough athreading.Eventthat the test waits on with a generous timeoutstopbecomes anEventthat the worker waits on (so shutdown is immediate rather than up to 200ms late)__init__so it is always available to the testfinallywith boundedjoin()calls plus anis_alive()assertion so a stuck thread fails loudly.Was generative AI tooling used to co-author this PR?