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 test BulkIntegrationIT.testDeleteIndexWhileIndexing #5491

Merged
merged 1 commit into from
Dec 9, 2022
Merged
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 @@ -193,34 +193,29 @@ public void testDeleteIndexWhileIndexing() throws Exception {
String index = "deleted_while_indexing";
createIndex(index);
AtomicBoolean stopped = new AtomicBoolean();
Thread[] threads = new Thread[between(1, 4)];
AtomicInteger docID = new AtomicInteger();
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread(() -> {
while (stopped.get() == false && docID.get() < 5000) {
String id = Integer.toString(docID.incrementAndGet());
try {
IndexResponse response = client().prepareIndex(index)
.setId(id)
.setSource(Collections.singletonMap("f" + randomIntBetween(1, 10), randomNonNegativeLong()), XContentType.JSON)
.get();
assertThat(response.getResult(), is(oneOf(CREATED, UPDATED)));
logger.info("--> index id={} seq_no={}", response.getId(), response.getSeqNo());
} catch (OpenSearchException ignore) {
logger.info("--> fail to index id={}", id);
}
Thread thread = new Thread(() -> {
while (stopped.get() == false && docID.get() < 5000) {
String id = Integer.toString(docID.incrementAndGet());
try {
IndexResponse response = client().prepareIndex(index)
.setId(id)
.setSource(Collections.singletonMap("f" + randomIntBetween(1, 10), randomNonNegativeLong()), XContentType.JSON)
.get();
assertThat(response.getResult(), is(oneOf(CREATED, UPDATED)));
logger.info("--> index id={} seq_no={}", response.getId(), response.getSeqNo());
} catch (OpenSearchException ignore) {
logger.info("--> fail to index id={}", id);
}
});
threads[i].start();
}
}
});
thread.start();
ensureGreen(index);
assertBusy(() -> assertThat(docID.get(), greaterThanOrEqualTo(1)));
assertAcked(client().admin().indices().prepareDelete(index));
stopped.set(true);
for (Thread thread : threads) {
thread.join(ReplicationRequest.DEFAULT_TIMEOUT.millis() / 2);
assertFalse(thread.isAlive());
}
thread.join(ReplicationRequest.DEFAULT_TIMEOUT.millis() / 2);
assertFalse(thread.isAlive());
}

}