Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Improve flaky BoundedElasticScheduler toString test #3010

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import reactor.util.Loggers;

import static org.assertj.core.api.Assertions.*;
import static org.awaitility.Awaitility.await;

/**
* @author Simon Baslé
Expand Down Expand Up @@ -757,7 +758,7 @@ void estimateRemainingTaskCapacityResetWhenDirectTaskIsExecuted() throws Interru

assertThat(boundedElasticScheduler.estimateRemainingTaskCapacity()).as("capacity when running").isZero();
latch.countDown();
Awaitility.await().untilTrue(taskRan);
await().untilTrue(taskRan);
assertThat(boundedElasticScheduler.estimateRemainingTaskCapacity()).as("capacity after run").isOne();
}

Expand Down Expand Up @@ -786,7 +787,7 @@ void estimateRemainingTaskCapacityResetWhenWorkerTaskIsExecuted() throws Interru

assertThat(boundedElasticScheduler.estimateRemainingTaskCapacity()).as("capacity when running").isZero();
latch.countDown();
Awaitility.await().untilTrue(taskRan);
await().untilTrue(taskRan);
assertThat(boundedElasticScheduler.estimateRemainingTaskCapacity()).as("capacity after run").isOne();
}

Expand Down Expand Up @@ -925,7 +926,7 @@ void taskPutInPendingQueueIsEventuallyExecuted() throws InterruptedException {
assertThat(boundedElasticScheduler.estimateRemainingTaskCapacity()).as("queue full").isZero();

latch.countDown();
Awaitility.await().atMost(100, TimeUnit.MILLISECONDS)
await().atMost(100, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.pollDelay(10, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertThat(ranSecond)
Expand Down Expand Up @@ -1463,13 +1464,16 @@ void toStringOfExecutorReflectsBoundedVsUnboundedAndCompletedVsQueued()
try {
bounded.submit(taskStartedLatch::countDown);
unbounded.submit(taskStartedLatch::countDown);
bounded.schedule(() -> {}, 100, TimeUnit.MILLISECONDS);
unbounded.schedule(() -> {}, 100, TimeUnit.MILLISECONDS);
bounded.schedule(() -> {}, 1, TimeUnit.SECONDS);
unbounded.schedule(() -> {}, 1, TimeUnit.SECONDS);

assertThat(taskStartedLatch.await(1, TimeUnit.SECONDS)).as("tasks picked").isTrue(); //give a small window for the task to be picked from the queue and completed

assertThat(bounded).hasToString("BoundedScheduledExecutorService{IDLE, queued=1/123, completed=1}");
assertThat(unbounded).hasToString("BoundedScheduledExecutorService{IDLE, queued=1/unbounded, completed=1}");
Awaitility.with().pollDelay(Duration.ofMillis(50))
.await().atMost(Duration.ofMillis(500)).untilAsserted(() -> {
assertThat(bounded).hasToString("BoundedScheduledExecutorService{IDLE, queued=1/123, completed=1}");
assertThat(unbounded).hasToString("BoundedScheduledExecutorService{IDLE, queued=1/unbounded, completed=1}");
});
}
finally {
bounded.shutdownNow();
Expand Down