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

Fix flaky tests 'testDeleteAllAndListAllPits' and 'testDeleteWhileSearch' #10946

Merged
merged 3 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

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

public void testDeleteAllAndListAllPits() throws IOException, InterruptedException {
public void testDeleteAllAndListAllPits() throws Exception {
CreatePitRequest pitRequest = new CreatePitRequest(new TimeValue(1, TimeUnit.DAYS), true, "index");
CreatePitResponse pitResponse = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);
CreatePitResponse pitResponse1 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);
Expand All @@ -91,31 +90,30 @@ public void testDeleteAllAndListAllPits() throws IOException, InterruptedExcepti
List<String> pits = getAllPitResponse.getPitInfos().stream().map(r -> r.getPitId()).collect(Collectors.toList());
assertTrue(pits.contains(pitResponse.getId()));
assertTrue(pits.contains(pitResponse1.getId()));
CountDownLatch countDownLatch = new CountDownLatch(1);
ActionListener<DeletePitResponse> deletePitListener = new ActionListener<>() {
@Override
public void onResponse(DeletePitResponse response) {
countDownLatch.countDown();
for (DeletePitInfo deletePitInfo : response.getDeletePitResults()) {
assertTrue(deletePitInfo.isSuccessful());
}
}

@Override
public void onFailure(Exception e) {
countDownLatch.countDown();
if (!(e instanceof OpenSearchStatusException)) {
throw new AssertionError("Delete all failed");
}
}
};
final CreatePitResponse pitResponse3 = execute(pitRequest, highLevelClient()::createPit, highLevelClient()::createPitAsync);

assertTrue(pitResponse3.getId() != null);
ActionListener<GetAllPitNodesResponse> getPitsListener = new ActionListener<GetAllPitNodesResponse>() {
@Override
public void onResponse(GetAllPitNodesResponse response) {
List<String> pits = response.getPitInfos().stream().map(r -> r.getPitId()).collect(Collectors.toList());
assertTrue(pits.contains(pitResponse3.getId()));
// delete all pits
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener);
}

@Override
Expand All @@ -126,11 +124,12 @@ public void onFailure(Exception e) {
}
};
highLevelClient().getAllPitsAsync(RequestOptions.DEFAULT, getPitsListener);
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener);
assertTrue(countDownLatch.await(10, TimeUnit.SECONDS));

// validate no pits case
getAllPitResponse = highLevelClient().getAllPits(RequestOptions.DEFAULT);
assertTrue(getAllPitResponse.getPitInfos().size() == 0);
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener);
assertBusy(() -> {
GetAllPitNodesResponse getAllPitResponse1 = highLevelClient().getAllPits(RequestOptions.DEFAULT);
assertTrue(getAllPitResponse1.getPitInfos().size() == 0);
highLevelClient().deleteAllPitsAsync(RequestOptions.DEFAULT, deletePitListener);
peternied marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ public void testDeleteWhileSearch() throws Exception {
private void verifySearchContextMissingException(ShardSearchFailure[] failures) {
for (ShardSearchFailure failure : failures) {
Throwable cause = ExceptionsHelper.unwrapCause(failure.getCause());
assertTrue(failure.toString(), cause instanceof SearchContextMissingException);
if (failure.toString().contains("reader_context is already closed can't increment refCount current count")) {
// this is fine, expected search error when context is already deleted
} else {
assertTrue(failure.toString(), cause instanceof SearchContextMissingException);
}
}
}

Expand Down
Loading