Skip to content

Commit 93181d3

Browse files
committed
Fixed flaky test: ResourceAwareTasksTests.testTaskIdPersistsInThreadContext
Signed-off-by: Ketan Verma <ketan9495@gmail.com>
1 parent 54364a5 commit 93181d3

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
5858
- [Segment Replication] Fix timeout issue by calculating time needed to process getSegmentFiles ([#4426](https://github.com/opensearch-project/OpenSearch/pull/4426))
5959
- [Bug]: gradle check failing with java heap OutOfMemoryError (([#4328](https://github.com/opensearch-project/OpenSearch/
6060
- `opensearch.bat` fails to execute when install path includes spaces ([#4362](https://github.com/opensearch-project/OpenSearch/pull/4362))
61+
- Fixed flaky test `ResourceAwareTasksTests.testTaskIdPersistsInThreadContext` ([#4484](https://github.com/opensearch-project/OpenSearch/pull/4484))
6162

6263
### Security
6364
- CVE-2022-25857 org.yaml:snakeyaml DOS vulnerability ([#4341](https://github.com/opensearch-project/OpenSearch/pull/4341))

server/src/test/java/org/opensearch/action/admin/cluster/node/tasks/ResourceAwareTasksTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.concurrent.CountDownLatch;
4343
import java.util.concurrent.ExecutionException;
4444
import java.util.concurrent.Future;
45+
import java.util.concurrent.TimeUnit;
4546
import java.util.concurrent.atomic.AtomicLong;
4647
import java.util.concurrent.atomic.AtomicReference;
4748
import java.util.function.BiConsumer;
@@ -616,6 +617,10 @@ public void onFailure(Exception e) {
616617

617618
taskTestContext.requestCompleteLatch.await();
618619

620+
// It is possible for the MockTaskManagerListener to be called after the response is sent already.
621+
// Wait enough time for taskId to be added to taskIdsRemovedFromThreadContext before performing validations.
622+
waitUntil(() -> taskIdsAddedToThreadContext.size() == taskIdsRemovedFromThreadContext.size(), 5, TimeUnit.SECONDS);
623+
619624
assertEquals(expectedTaskIdInThreadContext.get(), actualTaskIdInThreadContext.get());
620625
assertThat(taskIdsAddedToThreadContext, containsInAnyOrder(taskIdsRemovedFromThreadContext.toArray()));
621626
}

0 commit comments

Comments
 (0)