Skip to content

Commit

Permalink
Add waiting time to account for Thread.sleep inaccuracy
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <widdis@gmail.com>
  • Loading branch information
dbwiddis committed Dec 29, 2022
1 parent f2b5044 commit 091d02d
Showing 1 changed file with 19 additions and 9 deletions.
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
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

0 comments on commit 091d02d

Please sign in to comment.