This is an automated email from the ASF dual-hosted git repository.
JackieTien97 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new 5221cf49ed0 fix: make CompactionWorkerTest UT deterministic by using
CountDownLatch instead of fixed 2s sleep to wait for task drop status reset
(#18498)
5221cf49ed0 is described below
commit 5221cf49ed0e82e23ad9235ae78069b0659a5ea0
Author: shuwenwei <[email protected]>
AuthorDate: Thu Aug 20 11:08:36 2026 +0800
fix: make CompactionWorkerTest UT deterministic by using CountDownLatch
instead of fixed 2s sleep to wait for task drop status reset (#18498)
---
.../compaction/CompactionWorkerTest.java | 58 +++++++++++++++++++---
1 file changed, 52 insertions(+), 6 deletions(-)
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/CompactionWorkerTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/CompactionWorkerTest.java
index 11121d5bc01..ec1ec976e2b 100644
---
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/CompactionWorkerTest.java
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/compaction/CompactionWorkerTest.java
@@ -95,6 +95,15 @@ public class CompactionWorkerTest {
0);
CrossSpaceCompactionTask taskMock = Mockito.spy(task);
Mockito.doReturn(true).when(taskMock).start();
+ CountDownLatch statusResetLatch = new CountDownLatch(1);
+ Mockito.doAnswer(
+ invocation -> {
+ invocation.callRealMethod();
+ statusResetLatch.countDown();
+ return null;
+ })
+ .when(taskMock)
+ .resetCompactionCandidateStatusForAllSourceFiles();
FixedPriorityBlockingQueue<AbstractCompactionTask> queue =
new CompactionTaskQueue(50, new DefaultCompactionTaskComparatorImpl());
queue.put(taskMock);
@@ -108,7 +117,9 @@ public class CompactionWorkerTest {
}
});
thread.start();
- thread.join(TimeUnit.SECONDS.toMillis(2));
+ Assert.assertTrue(
+ "source files should be reset to NORMAL after the cross-space task is
dropped",
+ statusResetLatch.await(5, TimeUnit.SECONDS));
Assert.assertEquals(
0,
SystemInfo.getInstance().getCompactionMemoryBlock().getUsedMemoryInBytes());
Assert.assertEquals(0,
SystemInfo.getInstance().getCompactionFileNumCost().get());
@@ -153,6 +164,15 @@ public class CompactionWorkerTest {
0L, tsFileManager, sequenceFiles, unsequenceFiles, null, 1000,
0);
CrossSpaceCompactionTask taskMock = Mockito.spy(task);
Mockito.doReturn(true).when(taskMock).start();
+ CountDownLatch statusResetLatch = new CountDownLatch(1);
+ Mockito.doAnswer(
+ invocation -> {
+ invocation.callRealMethod();
+ statusResetLatch.countDown();
+ return null;
+ })
+ .when(taskMock)
+ .resetCompactionCandidateStatusForAllSourceFiles();
FixedPriorityBlockingQueue<AbstractCompactionTask> queue =
new CompactionTaskQueue(50, new
DefaultCompactionTaskComparatorImpl());
queue.put(taskMock);
@@ -165,7 +185,9 @@ public class CompactionWorkerTest {
}
});
thread.start();
- thread.join(TimeUnit.SECONDS.toMillis(2));
+ Assert.assertTrue(
+ "source files should be reset to NORMAL after the cross-space task
is dropped",
+ statusResetLatch.await(5, TimeUnit.SECONDS));
Assert.assertEquals(
0,
SystemInfo.getInstance().getCompactionMemoryBlock().getUsedMemoryInBytes());
Assert.assertEquals(0,
SystemInfo.getInstance().getCompactionFileNumCost().get());
@@ -208,9 +230,19 @@ public class CompactionWorkerTest {
CrossSpaceCompactionTask task =
new CrossSpaceCompactionTask(
0L, tsFileManager, sequenceFiles, unsequenceFiles, null, 1000, 0);
+ CrossSpaceCompactionTask taskMock = Mockito.spy(task);
+ CountDownLatch statusResetLatch = new CountDownLatch(1);
+ Mockito.doAnswer(
+ invocation -> {
+ invocation.callRealMethod();
+ statusResetLatch.countDown();
+ return null;
+ })
+ .when(taskMock)
+ .resetCompactionCandidateStatusForAllSourceFiles();
FixedPriorityBlockingQueue<AbstractCompactionTask> queue =
new CompactionTaskQueue(50, new DefaultCompactionTaskComparatorImpl());
- queue.put(task);
+ queue.put(taskMock);
Thread thread =
new Thread(
() -> {
@@ -220,7 +252,9 @@ public class CompactionWorkerTest {
}
});
thread.start();
- thread.join(TimeUnit.SECONDS.toMillis(2));
+ Assert.assertTrue(
+ "source files should be reset to NORMAL after the cross-space task is
dropped",
+ statusResetLatch.await(5, TimeUnit.SECONDS));
Assert.assertEquals(
0,
SystemInfo.getInstance().getCompactionMemoryBlock().getUsedMemoryInBytes());
Assert.assertEquals(0,
SystemInfo.getInstance().getCompactionFileNumCost().get());
@@ -248,9 +282,19 @@ public class CompactionWorkerTest {
// fail to check valid when tsfile manager is not allowed to compaction in
inner task
InnerSpaceCompactionTask innerTask =
new InnerSpaceCompactionTask(0L, tsFileManager, sequenceFiles, true,
null, 0L);
+ InnerSpaceCompactionTask innerTaskMock = Mockito.spy(innerTask);
+ CountDownLatch statusResetLatch = new CountDownLatch(1);
+ Mockito.doAnswer(
+ invocation -> {
+ invocation.callRealMethod();
+ statusResetLatch.countDown();
+ return null;
+ })
+ .when(innerTaskMock)
+ .resetCompactionCandidateStatusForAllSourceFiles();
FixedPriorityBlockingQueue<AbstractCompactionTask> queue =
new CompactionTaskQueue(50, new DefaultCompactionTaskComparatorImpl());
- queue.put(innerTask);
+ queue.put(innerTaskMock);
Thread thread =
new Thread(
() -> {
@@ -260,7 +304,9 @@ public class CompactionWorkerTest {
}
});
thread.start();
- thread.join(TimeUnit.SECONDS.toMillis(2));
+ Assert.assertTrue(
+ "source files should be reset to NORMAL after the inner-space task is
dropped",
+ statusResetLatch.await(5, TimeUnit.SECONDS));
Assert.assertEquals(
0,
SystemInfo.getInstance().getCompactionMemoryBlock().getUsedMemoryInBytes());
Assert.assertEquals(0,
SystemInfo.getInstance().getCompactionFileNumCost().get());