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 SearchCancellationIT tests to avoid race condition #5656

Merged
merged 4 commits into from
Dec 29, 2022
Merged
Changes from 1 commit
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 @@ -241,7 +241,8 @@ public void testCancellationDuringQueryPhaseUsingRequestParameter() throws Excep
.execute();
awaitForBlock(plugins);
// sleep for cancellation timeout to ensure scheduled cancellation task is actually executed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is no longer accurate. How about a static sleepForTimeout() or similar method so you only have to write the comment once?

Also, any idea why 2 seconds is used everywhere here? Would be great to make that something shorter (like 100ms) to speed up the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I was having so much fun copying and pasting with The Key. Sure, I'll make a static call. Not sure what the best minimum should be, but I'm guessing I could make it 1 second at least?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. You'll make it twice as fast!

Thread.sleep(cancellationTimeout.getMillis());
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
// unblock the search thread
disableBlocks(plugins);
ensureSearchWasCancelled(searchResponse);
Expand All @@ -263,7 +264,8 @@ public void testCancellationDuringQueryPhaseUsingClusterSetting() throws Excepti
.execute();
awaitForBlock(plugins);
// sleep for cluster cancellation timeout to ensure scheduled cancellation task is actually executed
Thread.sleep(cancellationTimeout.getMillis());
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
// unblock the search thread
disableBlocks(plugins);
ensureSearchWasCancelled(searchResponse);
Expand Down Expand Up @@ -295,7 +297,8 @@ public void testCancellationDuringFetchPhaseUsingRequestParameter() throws Excep
.execute();
awaitForBlock(plugins);
// sleep for request cancellation timeout to ensure scheduled cancellation task is actually executed
Thread.sleep(cancellationTimeout.getMillis());
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
// unblock the search thread
disableBlocks(plugins);
ensureSearchWasCancelled(searchResponse);
Expand Down Expand Up @@ -335,7 +338,9 @@ public void testCancellationOfFirstScrollSearchRequestUsingRequestParameter() th
.execute();

awaitForBlock(plugins);
Thread.sleep(cancellationTimeout.getMillis());
// sleep for request cancellation timeout to ensure scheduled cancellation task is actually executed
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
disableBlocks(plugins);
SearchResponse response = ensureSearchWasCancelled(searchResponse);
if (response != null) {
Expand Down Expand Up @@ -419,7 +424,8 @@ public void testNoCancellationOfScrollSearchOnFollowUpRequest() throws Exception

awaitForBlock(plugins);
// sleep for cancellation timeout to ensure there is no scheduled task for cancellation
Thread.sleep(cancellationTimeout.getMillis());
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
disableBlocks(plugins);

// wait for response and ensure there is no failure
Expand All @@ -445,7 +451,8 @@ public void testDisableCancellationAtRequestLevel() throws Exception {
.execute();
awaitForBlock(plugins);
// sleep for cancellation timeout to ensure there is no scheduled task for cancellation
Thread.sleep(cancellationTimeout.getMillis());
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
// unblock the search thread
disableBlocks(plugins);
// ensure search was successful since cancellation was disabled at request level
Expand All @@ -467,7 +474,8 @@ public void testDisableCancellationAtClusterLevel() throws Exception {
.execute();
awaitForBlock(plugins);
// sleep for cancellation timeout to ensure there is no scheduled task for cancellation
Thread.sleep(cancellationTimeout.getMillis());
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
// unblock the search thread
disableBlocks(plugins);
// ensure search was successful since cancellation was disabled at request level
Expand Down Expand Up @@ -527,7 +535,8 @@ public void testMSearchChildRequestCancellationWithClusterLevelTimeout() throws
.execute();
awaitForBlock(plugins);
// sleep for cluster cancellation timeout to ensure scheduled cancellation task is actually executed
Thread.sleep(cancellationTimeout.getMillis());
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(cancellationTimeout.getMillis() + 100L);
// unblock the search thread
disableBlocks(plugins);
// both child requests are expected to fail
Expand Down Expand Up @@ -582,7 +591,8 @@ public void testMSearchChildReqCancellationWithHybridTimeout() throws Exception
.execute();
awaitForBlock(plugins);
// sleep for cluster cancellation timeout to ensure scheduled cancellation task is actually executed
Thread.sleep(Math.max(reqCancellationTimeout.getMillis(), clusterCancellationTimeout.getMillis()));
// add 100ms to account for multithreading and sleep inaccuracies
Thread.sleep(Math.max(reqCancellationTimeout.getMillis(), clusterCancellationTimeout.getMillis()) + 100L);
// unblock the search thread
disableBlocks(plugins);
// only first and last child request are expected to fail
Expand Down