Skip to content

fix: serialize HandleGuard tests to prevent DESTROY_CALL_COUNT race#421

Merged
streamer45 merged 1 commit into
mainfrom
devin/1778525531-fix-flaky-guard-test
May 11, 2026
Merged

fix: serialize HandleGuard tests to prevent DESTROY_CALL_COUNT race#421
streamer45 merged 1 commit into
mainfrom
devin/1778525531-fix-flaky-guard-test

Conversation

@staging-devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Multiple tests share a global static DESTROY_CALL_COUNT: AtomicUsize in test_stubs. Each test resets it with .store(0, SeqCst) before running, but cargo test runs tests in parallel by default. When two tests using this counter run concurrently, one test's .store(0) can race with another test's fetch_add(1), causing incorrect assertion values and flaky failures (particularly handle_guard_catches_panic_between_create_and_ok).

Fix: Added a GUARD_TEST_MUTEX: std::sync::Mutex<()> in test_stubs and locked it at the start of each test that uses DESTROY_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_drop
  • handle_guard_calls_destroy_on_drop
  • handle_guard_does_not_destroy_when_defused
  • handle_guard_catches_panic_between_create_and_ok

Review & Testing Checklist for Human

  • Verify that the mutex is acquired before every DESTROY_CALL_COUNT.store(0, ...) call in tests (crates/plugin-native/src/wrapper.rs)
  • Run cargo test -p streamkit-plugin-native multiple times (e.g. 10 runs) to confirm the flaky test no longer fails

Notes

The handle_guard_catches_panic_between_create_and_ok test uses catch_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

Signed-off-by: StreamKit Devin <devin@streamkit.dev>
Co-Authored-By: Claudio Costa <cstcld91@gmail.com>
@staging-devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@streamer45 streamer45 enabled auto-merge (squash) May 11, 2026 19:27
@streamer45 streamer45 merged commit e8656c6 into main May 11, 2026
16 checks passed
@streamer45 streamer45 deleted the devin/1778525531-fix-flaky-guard-test branch May 11, 2026 19:37
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