CAMEL-23899: Fix flaky test LogWriterRollOverUpdateAsyncWithContentionTest#24416
Conversation
…nTest The test was flaky because runTest() only waited for the generate task to complete (via a CountDownLatch) before reading the log file and asserting all entries were PROCESSED. The update task, which marks records as committed, could still be running - causing assertions to fail on entries still in NEW state. Fix: Replace the insufficient latch-based synchronization with Awaitility to wait for both the generate and update tasks to complete via ExecutorService termination. Also flush the LogWriter before reading to ensure all data is persisted to disk. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 1 tested, 0 compile-only — current: 9 all testedMaveniverse Scalpel detected 1 affected modules (current approach: 9). Modules only in current approach (8)
Skip-tests mode would test 1 modules (1 direct + 0 downstream), skip tests for 0 (generated code, meta-modules) Modules Scalpel would test (1)
All tested modules (9 modules)
|
There was a problem hiding this comment.
Pull request overview
This PR stabilizes the camel-wal async rollover/update tests by ensuring verification only starts after both the record-generation and record-update tasks have completed, preventing races where entries are still in NEW state.
Changes:
- Remove the latch-based “generate-only” synchronization from the async test subclasses.
- In the shared base test, wait for executor termination using Awaitility and propagate task failures via
Future.get(). - Flush
LogWriterbefore reading back the file to verify persisted entry states.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| components/camel-wal/src/test/java/org/apache/camel/component/wal/LogWriterRollOverUpdateAsyncWithContentionTest.java | Removes latch countdown from async generation path to rely on base-class task completion waiting. |
| components/camel-wal/src/test/java/org/apache/camel/component/wal/LogWriterRollOverUpdateAsyncTest.java | Removes latch countdown from async generation path to rely on base-class task completion waiting. |
| components/camel-wal/src/test/java/org/apache/camel/component/wal/LogWriterRollOverUpdateAsyncBase.java | Replaces latch wait with Awaitility-based executor termination wait, propagates async exceptions, and flushes before verification. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Wrap the test body in a try-finally to ensure the executor service is always forcefully shut down, preventing thread leaks if Awaitility times out or another runtime failure occurs before termination. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
Fixes the flaky test
LogWriterRollOverUpdateAsyncWithContentionTest.testReadWriteUpdateRecordsWithRollOverin camel-wal.Root cause:
runTest()only waited for the generate task to complete (via aCountDownLatch) before reading the log file and asserting all entries were inPROCESSEDstate. The update task — which marks records as committed — could still be running, causing assertions to fail on entries still inNEWstate. This was especially pronounced with larger queue capacities (3000, 4000) where the producer finishes quickly while the consumer is still draining the queue.Fix:
ExecutorServiceterminationLogWriterbefore reading to ensure all data is persisted to disk before verificationCountDownLatchfield andlatch.countDown()calls from both subclass testsTest plan
LogWriterRollOverUpdateAsyncWithContentionTestpasses all 8 parameterized casesLogWriterRollOverUpdateAsyncTest(sibling test) passes without regressionClaude Code on behalf of Guillaume Nodet
🤖 Generated with Claude Code