You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "shuwenwei (via GitHub)" <gi...@apache.org> on 2026/08/20 02:40:03 UTC

[PR] Fix flaky CompactionWorkerTest by replacing fixed sleep with CountDownLatch [iotdb]

shuwenwei opened a new pull request, #18498:
URL: https://github.com/apache/iotdb/pull/18498

   ## Problem
   
   `CompactionWorkerTest.testFailedToAllocateFileNumInCrossTask` and `testFailedToCheckValidInCrossTask` intermittently fail with:
   
   ```
   expected:<NORMAL> but was:<COMPACTION_CANDIDATE>
   ```
   
   The tests use `thread.join(2s)` to wait for the compaction task to be dropped. However, in these failure cases `queue.take()` never returns: the task is dropped by `CompactionTaskQueue.prepareTask -> dropCompactionTask`, which calls `resetCompactionCandidateStatusForAllSourceFiles()` to change the source files from `COMPACTION_CANDIDATE` back to `NORMAL`. The worker thread then loops back and waits on the empty queue.
   
   The fixed 2-second join only waits for elapsed time, not for the actual state transition. Under load or scheduling delay, the main thread can assert before the worker thread performs the status reset, producing the flaky failure.
   
   ## Fix
   
   Replace the timing-based wait with a `CountDownLatch` triggered inside the worker thread at the exact state-transition point. A Mockito `doAnswer` hook calls `countDown()` right after `resetCompactionCandidateStatusForAllSourceFiles()` completes:
   
   ```java
   CountDownLatch statusResetLatch = new CountDownLatch(1);
   Mockito.doAnswer(invocation -> {
     invocation.callRealMethod();
     statusResetLatch.countDown();
     return null;
   }).when(taskMock).resetCompactionCandidateStatusForAllSourceFiles();
   
   thread.start();
   Assert.assertTrue(statusResetLatch.await(5, TimeUnit.SECONDS));
   ```
   
   This waits for the exact condition (source files back to `NORMAL`) with a 5-second timeout, making the tests deterministic instead of relying on arbitrary sleep.
   
   Applied to all four task-drop tests in `CompactionWorkerTest` that used the same pattern.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix flaky CompactionWorkerTest by replacing fixed sleep with CountDownLatch [iotdb]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #18498:
URL: https://github.com/apache/iotdb/pull/18498#issuecomment-5350657627

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18498) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [B Reliability Rating on New Code](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18498) (required ≥ A)  
     
   <!-- sqra:qg_revision=beb0e3d0c8fd7b82b30ab4fc7413de1840cd163dddcf10bcd9e9ba6bbe9e588c -->
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_iotdb&pullRequest=18498)
   
   ##   
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/light_bulb-16px.png '') Catch issues before they fail your Quality Gate with our IDE extension ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/sonarlint-16px.png '') [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix flaky CompactionWorkerTest by replacing fixed sleep with CountDownLatch [iotdb]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #18498:
URL: https://github.com/apache/iotdb/pull/18498#issuecomment-5350972687

   ## [Codecov](https://app.codecov.io/gh/apache/iotdb/pull/18498?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 43.95%. Comparing base ([`ada62cb`](https://app.codecov.io/gh/apache/iotdb/commit/ada62cb1048b85507cbc478edd4ebd50af037ac5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`03920be`](https://app.codecov.io/gh/apache/iotdb/commit/03920bec5100ff238142c51bd311e76110a270b1?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #18498      +/-   ##
   ============================================
   - Coverage     43.95%   43.95%   -0.01%     
     Complexity      374      374              
   ============================================
     Files          5402     5402              
     Lines        388198   388198              
     Branches      50694    50694              
   ============================================
   - Hits         170633   170623      -10     
   - Misses       217565   217575      +10     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/iotdb/pull/18498?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Fix flaky CompactionWorkerTest by replacing fixed sleep with CountDownLatch [iotdb]

Posted by "JackieTien97 (via GitHub)" <gi...@apache.org>.
JackieTien97 merged PR #18498:
URL: https://github.com/apache/iotdb/pull/18498


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org