Skip to content

test: remove timing race in stopped-pending serialize test#290

Open
ZheSun88 wants to merge 1 commit into
mainfrom
fix/flaky-stopped-pending-serialization-test
Open

test: remove timing race in stopped-pending serialize test#290
ZheSun88 wants to merge 1 commit into
mainfrom
fix/flaky-stopped-pending-serialization-test

Conversation

@ZheSun88

@ZheSun88 ZheSun88 commented May 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Replace Thread.sleep(300) in onSerializationSuccess with a CountDownLatch so the second serialize() call deterministically runs while the first serialization is still pending.
  • Issue the second serialize() on a separate thread (it now blocks in waitForSerialization()) and assert it stays blocked until the latch is released, proving it took the "wait for pending" branch rather than the executor path.

Why

The previous pattern relied on the 300 ms sleep outlasting awaitility's poll for !isRunning(). On slow runners the sleep could finish first, letting stop() shut down the executor before the second serialize() ran. The second call would then fall through to CompletableFuture.runAsync(..., executorService) and throw RejectedExecutionException — observed on the validation run for #289 (job log) where dependency upgrades shifted timings enough to expose the race. This follows the same CountDownLatch pattern introduced in #283 for two sibling tests.

Test plan

  • mvn test -Dtest='SessionSerializerTest#serialize_applicationStopped_serializationRequestWhilePendingSerialization_ignoreAndWaitForCompletion' passes locally (5/5 runs).
  • mvn test -Dtest='SessionSerializerTest' — full 25-test class passes.
  • CI validation workflow passes.

🤖 Generated with Claude Code

Replace Thread.sleep-based serialization gating with a CountDownLatch so
the second serialize() call always runs while the first serialization is
still pending. The previous pattern relied on the 300 ms sleep
outlasting awaitility's poll for !isRunning(); on slow runners the sleep
could finish first, letting stop() shut down the executor before the
second serialize() ran, which then hit RejectedExecutionException
instead of taking the expected "wait for pending" branch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

 35 files  ±0   35 suites  ±0   29s ⏱️ ±0s
179 tests ±0  178 ✅ ±0   1 💤 ±0  0 ❌ ±0 
236 runs  ±0  203 ✅ ±0  33 💤 ±0  0 ❌ ±0 

Results for commit 784b114. ± Comparison against base commit 3d224e9.

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.

1 participant