Skip to content

Commit dcfe64e

Browse files
[CI] Fix bogus ScheduleWithFixedDelayTests.testRunnableRunsAtMostOnceAfterCancellation
Closes #34004
1 parent f1f0687 commit dcfe64e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

server/src/test/java/org/elasticsearch/threadpool/ScheduleWithFixedDelayTests.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
import java.util.concurrent.atomic.AtomicReference;
4141

4242
import static org.hamcrest.Matchers.containsString;
43+
import static org.hamcrest.Matchers.equalTo;
4344
import static org.hamcrest.Matchers.instanceOf;
44-
import static org.hamcrest.Matchers.isOneOf;
4545
import static org.hamcrest.Matchers.sameInstance;
4646
import static org.mockito.Mockito.mock;
4747
import static org.mockito.Mockito.times;
@@ -266,26 +266,28 @@ public ScheduledFuture<?> schedule(TimeValue delay, String executor, Runnable co
266266
assertTrue(reschedulingRunnable.isCancelled());
267267
}
268268

269-
public void testRunnableRunsAtMostOnceAfterCancellation() throws Exception {
270-
final int iterations = scaledRandomIntBetween(1, 12);
269+
public void testRunnableDoesNotRunAfterCancellation() throws Exception {
270+
final int iterations = scaledRandomIntBetween(2, 12);
271271
final AtomicInteger counter = new AtomicInteger();
272272
final CountDownLatch doneLatch = new CountDownLatch(iterations);
273273
final Runnable countingRunnable = () -> {
274274
counter.incrementAndGet();
275275
doneLatch.countDown();
276276
};
277277

278-
final Cancellable cancellable = threadPool.scheduleWithFixedDelay(countingRunnable, TimeValue.timeValueMillis(10L), Names.GENERIC);
278+
final TimeValue interval = TimeValue.timeValueMillis(50L);
279+
final Cancellable cancellable = threadPool.scheduleWithFixedDelay(countingRunnable, interval, Names.GENERIC);
279280
doneLatch.await();
280281
cancellable.cancel();
282+
281283
final int counterValue = counter.get();
282-
assertThat(counterValue, isOneOf(iterations, iterations + 1));
284+
assertThat(counterValue, equalTo(iterations));
283285

284286
if (rarely()) {
285287
awaitBusy(() -> {
286288
final int value = counter.get();
287-
return value == iterations || value == iterations + 1;
288-
}, 50L, TimeUnit.MILLISECONDS);
289+
return value == iterations;
290+
}, 5 * interval.millis(), TimeUnit.MILLISECONDS);
289291
}
290292
}
291293

0 commit comments

Comments
 (0)