Skip to content

Commit 071d549

Browse files
authored
Fix race condition in async task reschedule test (#137405)
When rescheduling a task, the task may begin running before the test is able to take more actions. This means reseting the barriers in the auto reschedule test may occur after the second run of the task has begun, which results in a broken barrier. This commit fixes the race condition by moving the reset of each barrier to occur after the await for the relevant barrier. This ensures that each barrier is ready to be awaited on again by the end of the run. Due to there being two barriers, the second barrier may be reset after the test codes second barrier1.await, but that is ok. closes #131150
1 parent 7d4c25d commit 071d549

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

server/src/test/java/org/elasticsearch/common/util/concurrent/AbstractAsyncTaskTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ protected void runInternal() {
6262
logger.error("barrier1 interrupted", e);
6363
fail("interrupted");
6464
}
65+
barrier1.reset();
66+
6567
count.incrementAndGet();
6668
try {
6769
barrier2.await();
6870
} catch (Exception e) {
6971
logger.error("barrier2 interrupted", e);
7072
fail("interrupted");
7173
}
74+
barrier2.reset();
75+
7276
if (shouldRunThrowException) {
7377
throw new RuntimeException("foo");
7478
}
@@ -83,8 +87,8 @@ protected void runInternal() {
8387
assertTrue(task.isScheduled());
8488
barrier2.await();
8589
assertEquals(1, count.get());
86-
barrier1.reset();
87-
barrier2.reset();
90+
91+
// wait for the rescheduled task to begin running
8892
barrier1.await();
8993
assertTrue(task.isScheduled());
9094
task.close();

0 commit comments

Comments
 (0)