This is an automated email from the ASF dual-hosted git repository. cshannon pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new 6d94f545b6 Fix flaky CompactionJobQueuesTest (#5017) 6d94f545b6 is described below commit 6d94f545b6ef5bab31c9e086c0dbfaa362bb52fd Author: Christopher L. Shannon <cshan...@apache.org> AuthorDate: Fri Oct 25 18:30:29 2024 -0400 Fix flaky CompactionJobQueuesTest (#5017) Fix testGetAsync() by ensuring that future6 will timeout before adding a job to the queue by waiting for the TimeoutException to happen and not arbitrarily sleeping. Before it was possible for the job to be added to the queue in rare cases before the timeout executed so future6 was receiving the job and not future7 which caused the test to fail. This closes #5005 --- .../manager/compaction/queue/CompactionJobQueuesTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobQueuesTest.java b/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobQueuesTest.java index bba27daf67..3d8933fa38 100644 --- a/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobQueuesTest.java +++ b/server/manager/src/test/java/org/apache/accumulo/manager/compaction/queue/CompactionJobQueuesTest.java @@ -20,7 +20,9 @@ package org.apache.accumulo.manager.compaction.queue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.net.URI; @@ -29,9 +31,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Optional; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; @@ -46,7 +50,6 @@ import org.apache.accumulo.core.metadata.schema.TabletMetadata; import org.apache.accumulo.core.spi.compaction.CompactionJob; import org.apache.accumulo.core.spi.compaction.CompactionKind; import org.apache.accumulo.core.spi.compaction.CompactorGroupId; -import org.apache.accumulo.core.util.UtilWaitThread; import org.apache.accumulo.core.util.compaction.CompactionJobImpl; import org.apache.hadoop.io.Text; import org.junit.jupiter.api.Test; @@ -393,8 +396,10 @@ public class CompactionJobQueuesTest { var future6 = jobQueues.getAsync(cg1); assertFalse(future6.isDone()); future6.orTimeout(10, TimeUnit.MILLISECONDS); - // sleep for 20 millis, this should cause future6 to be timed out - UtilWaitThread.sleep(20); + // Wait for future6 to timeout to make sure future7 will + // receive the job when added to the queue + var ex = assertThrows(ExecutionException.class, future6::get); + assertInstanceOf(TimeoutException.class, ex.getCause()); var future7 = jobQueues.getAsync(cg1); assertFalse(future7.isDone()); // since future5 was canceled and future6 timed out, this addition should go to future7