From 091d02d8d1984c2002cf49d03b714c2696415cf3 Mon Sep 17 00:00:00 2001 From: Daniel Widdis Date: Thu, 29 Dec 2022 09:05:50 -0800 Subject: [PATCH] Add waiting time to account for Thread.sleep inaccuracy Signed-off-by: Daniel Widdis --- .../search/SearchCancellationIT.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java b/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java index da5698918cf99..baf6d93a82362 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/SearchCancellationIT.java @@ -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); @@ -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); @@ -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); @@ -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) { @@ -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 @@ -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 @@ -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 @@ -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 @@ -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