(fix) tests: fix flaky TestTwistedConnection.test_connection_initialization#767
Open
mykaul wants to merge 1 commit intoscylladb:masterfrom
Open
(fix) tests: fix flaky TestTwistedConnection.test_connection_initialization#767mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul wants to merge 1 commit intoscylladb:masterfrom
Conversation
Author
|
reviewed with Opus 4.6 and GPT-5.4 |
Author
|
Failure seen @ #748 |
Patch reactor.running to False in setUp() so that maybe_start() always enters the branch that spawns the reactor thread. Without this, leaked global reactor state from prior tests can leave reactor.running as True, causing maybe_start() to skip thread creation and the reactor.run mock to never be called — making the assertion in test_connection_initialization fail intermittently. Observed in CI on PyPy 3.11 + macOS x86 (Rosetta 2), where timing differences make the reactor state leak more likely.
8db899e to
7aafd82
Compare
8 tasks
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.
Motivation
TestTwistedConnection::test_connection_initializationis flaky in CI. It was observed failing on PyPy 3.11 + macOS x86 (Rosetta 2) in this CI run, but it can fail on any platform where the Twisted reactor's globalrunningstate leaks between tests.The root cause:
TwistedLoop.maybe_start()checksreactor.runningto decide whether to spawn a new reactor thread. If a prior test leavesreactor.running == True,maybe_start()becomes a no-op, thereactor.runmock is never called, and the assertion at line 116 fails:Change
Patch
twisted.internet.reactor.runningtoFalseinTestTwistedConnection.setUp(), ensuringmaybe_start()always enters the branch that spawns the reactor thread regardless of leaked global state. The patcher is properly stopped intearDown().Testing
test_twistedreactor.pypass.