fix: serialize HandleGuard tests to prevent DESTROY_CALL_COUNT race#421
Merged
Conversation
Signed-off-by: StreamKit Devin <devin@streamkit.dev> Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Multiple tests share a global static
DESTROY_CALL_COUNT: AtomicUsizeintest_stubs. Each test resets it with.store(0, SeqCst)before running, butcargo testruns tests in parallel by default. When two tests using this counter run concurrently, one test's.store(0)can race with another test'sfetch_add(1), causing incorrect assertion values and flaky failures (particularlyhandle_guard_catches_panic_between_create_and_ok).Fix: Added a
GUARD_TEST_MUTEX: std::sync::Mutex<()>intest_stubsand locked it at the start of each test that usesDESTROY_CALL_COUNT. This serializes only the tests that share this global state, without affecting other tests.Affected tests (4 total):
instance_state_drop_destroys_without_request_drophandle_guard_calls_destroy_on_drophandle_guard_does_not_destroy_when_defusedhandle_guard_catches_panic_between_create_and_okReview & Testing Checklist for Human
DESTROY_CALL_COUNT.store(0, ...)call in tests (crates/plugin-native/src/wrapper.rs)cargo test -p streamkit-plugin-nativemultiple times (e.g. 10 runs) to confirm the flaky test no longer failsNotes
The
handle_guard_catches_panic_between_create_and_oktest usescatch_unwind, so the panic is caught and the mutex is released cleanly (no poisoning).Link to Devin session: https://staging.itsdev.in/sessions/03dd4d8fe520447e88bf26c8cfc9c9e8
Requested by: @streamer45