fix: test_successful_wait_for_connection test: make HashableMock thread-safe to fix flaky Windows CI#766
Draft
mykaul wants to merge 1 commit intoscylladb:masterfrom
Draft
Conversation
…ixin NonCallableMagicMock.__init__ (via MagicMixin) replaces __hash__ on the type with a MagicMock object. That MagicMock is not thread-safe, so concurrent hash() calls — e.g. `connection in self._trash` in pool.py return_connection — can raise `TypeError: __hash__ method should return an integer` under concurrent access on Windows. The previous __hash__ override was dead code: MagicMixin.__init__ always replaced it with a MagicMock before any test could call it. Fix by restoring a plain function as the class-level __hash__ after super().__init__ runs, so hash() always resolves to a real function instead of a thread-unsafe MagicMock callable. Fixes flaky test_successful_wait_for_connection on Windows CI.
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.
Summary
Fixes flaky
test_successful_wait_for_connectionfailure on Windows CI:at
cassandra/pool.py:582(connection in self._trash).Root cause
HashableMocksubclassesNonCallableMagicMockand overrides__hash__to returnid(self). However,MagicMixin.__init__replaces__hash__on the type with aMagicMockobject before any test runs — making the original override dead code that never executes.The
MagicMockstanding in for__hash__happens to return a hash-compatible value in single-threaded use, butMagicMock.__call__is not thread-safe. Intest_successful_wait_for_connection, two threads callpool.return_connection()on the sameHashableMockconcurrently, which triggershash()viaconnection in self._trash(asetmembership check). Under Windows thread scheduling, the concurrentMagicMock.__call__can return a non-integer, causing theTypeError.Fix
Restore a plain function as the class-level
__hash__inHashableMock.__init__, afterMagicMixinhas finished its work. This ensureshash()always resolves to a real, thread-safe function returningid(self).Verification
test_successful_wait_for_connectionpasses 100/100 runs in a loopPre-review checklist
./docs/source/.Fixes:annotations to PR description.