mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
[CI] Fix bogus ScheduleWithFixedDelayTests.testRunnableRunsAtMostOnceAfterCancellation
Closes #34004
This commit is contained in:
parent
f1f0687b57
commit
dcfe64e0e4
@ -40,8 +40,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.isOneOf;
|
|
||||||
import static org.hamcrest.Matchers.sameInstance;
|
import static org.hamcrest.Matchers.sameInstance;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@ -266,8 +266,8 @@ public class ScheduleWithFixedDelayTests extends ESTestCase {
|
|||||||
assertTrue(reschedulingRunnable.isCancelled());
|
assertTrue(reschedulingRunnable.isCancelled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRunnableRunsAtMostOnceAfterCancellation() throws Exception {
|
public void testRunnableDoesNotRunAfterCancellation() throws Exception {
|
||||||
final int iterations = scaledRandomIntBetween(1, 12);
|
final int iterations = scaledRandomIntBetween(2, 12);
|
||||||
final AtomicInteger counter = new AtomicInteger();
|
final AtomicInteger counter = new AtomicInteger();
|
||||||
final CountDownLatch doneLatch = new CountDownLatch(iterations);
|
final CountDownLatch doneLatch = new CountDownLatch(iterations);
|
||||||
final Runnable countingRunnable = () -> {
|
final Runnable countingRunnable = () -> {
|
||||||
@ -275,17 +275,19 @@ public class ScheduleWithFixedDelayTests extends ESTestCase {
|
|||||||
doneLatch.countDown();
|
doneLatch.countDown();
|
||||||
};
|
};
|
||||||
|
|
||||||
final Cancellable cancellable = threadPool.scheduleWithFixedDelay(countingRunnable, TimeValue.timeValueMillis(10L), Names.GENERIC);
|
final TimeValue interval = TimeValue.timeValueMillis(50L);
|
||||||
|
final Cancellable cancellable = threadPool.scheduleWithFixedDelay(countingRunnable, interval, Names.GENERIC);
|
||||||
doneLatch.await();
|
doneLatch.await();
|
||||||
cancellable.cancel();
|
cancellable.cancel();
|
||||||
|
|
||||||
final int counterValue = counter.get();
|
final int counterValue = counter.get();
|
||||||
assertThat(counterValue, isOneOf(iterations, iterations + 1));
|
assertThat(counterValue, equalTo(iterations));
|
||||||
|
|
||||||
if (rarely()) {
|
if (rarely()) {
|
||||||
awaitBusy(() -> {
|
awaitBusy(() -> {
|
||||||
final int value = counter.get();
|
final int value = counter.get();
|
||||||
return value == iterations || value == iterations + 1;
|
return value == iterations;
|
||||||
}, 50L, TimeUnit.MILLISECONDS);
|
}, 5 * interval.millis(), TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user