Skip to content

Commit 6fd6f87

Browse files
Fixing PIT flaky tests
Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
1 parent ebbddd3 commit 6fd6f87

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
2121
- [Segment Replication] Add snapshot and restore tests for segment replication feature ([#3993](https://github.com/opensearch-project/OpenSearch/pull/3993))
2222
- Added missing javadocs for `:example-plugins` modules ([#4540](https://github.com/opensearch-project/OpenSearch/pull/4540))
2323
- Add missing Javadoc tag descriptions in unit tests ([#4629](https://github.com/opensearch-project/OpenSearch/pull/4629))
24+
- Fixing PIT flaky tests ([4632](https://github.com/opensearch-project/OpenSearch/pull/4632))
2425
### Dependencies
2526
- Bumps `log4j-core` from 2.18.0 to 2.19.0
2627

client/rest-high-level/src/test/java/org/opensearch/client/PitIT.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.IOException;
2525
import java.util.ArrayList;
2626
import java.util.List;
27+
import java.util.concurrent.CountDownLatch;
2728
import java.util.concurrent.TimeUnit;
2829
import java.util.stream.Collectors;
2930

@@ -71,7 +72,7 @@ public void testCreateAndDeletePit() throws IOException {
7172
assertTrue(deletePitResponse.getDeletePitResults().get(0).getPitId().equals(createPitResponse.getId()));
7273
}
7374

74-
public void testDeleteAllAndListAllPits() throws IOException {
75+
public void testDeleteAllAndListAllPits() throws IOException, InterruptedException {
7576
CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "index");
7677
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);
7778
CreatePitResponse pitResponse1 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);
@@ -90,16 +91,19 @@ public void testDeleteAllAndListAllPits() throws IOException {
9091
List<String> pits = getAllPitResponse.getPitInfos().stream().map(r -> r.getPitId()).collect(Collectors.toList());
9192
assertTrue(pits.contains(pitResponse.getId()));
9293
assertTrue(pits.contains(pitResponse1.getId()));
94+
CountDownLatch countDownLatch = new CountDownLatch(1);
9395
ActionListener<DeletePitResponse> deletePitListener = new ActionListener<>() {
9496
@Override
9597
public void onResponse(DeletePitResponse response) {
98+
countDownLatch.countDown();
9699
for (DeletePitInfo deletePitInfo : response.getDeletePitResults()) {
97100
assertTrue(deletePitInfo.isSuccessful());
98101
}
99102
}
100103

101104
@Override
102105
public void onFailure(Exception e) {
106+
countDownLatch.countDown();
103107
if (!(e instanceof OpenSearchStatusException)) {
104108
throw new AssertionError("Delete all failed");
105109
}
@@ -123,6 +127,7 @@ public void onFailure(Exception e) {
123127
};
124128
highLevelClient().getAllPitsAsync(RequestOptions.DEFAULT, getPitsListener);
125129
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener);
130+
countDownLatch.await(10, TimeUnit.SECONDS);
126131
// validate no pits case
127132
getAllPitResponse = highLevelClient().getAllPits(RequestOptions.DEFAULT);
128133
assertTrue(getAllPitResponse.getPitInfos().size() == 0);

server/src/test/java/org/opensearch/search/PitMultiNodeTests.java

-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ public Settings onNodeStopped(String nodeName) throws Exception {
9898
ActionFuture<CreatePitResponse> execute = client().execute(CreatePitAction.INSTANCE, request);
9999
ExecutionException ex = expectThrows(ExecutionException.class, execute::get);
100100
assertTrue(ex.getMessage().contains("Failed to execute phase [create_pit]"));
101-
assertTrue(ex.getMessage().contains("Partial shards failure"));
102101
validatePitStats("index", 0, 0);
103102
return super.onNodeStopped(nodeName);
104103
}

0 commit comments

Comments
 (0)