From 27962077bc0afbb50cf4443c55b8cb81b76ecd85 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 14 Jun 2024 16:30:20 +0800 Subject: [PATCH] Fix flaky ITs (#332) (#333) * Fix flaky ITs * fix compilation error --------- (cherry picked from commit 30bd9898351e9064f46a25f27ff27131f5257866) Signed-off-by: zane-neo Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../SearchAnomalyDetectorsToolTests.java | 54 +++++++++---------- .../integTest/SearchAnomalyResultsToolIT.java | 5 +- .../integTest/SearchMonitorsToolIT.java | 13 ++--- 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java b/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java index 407690f6..e0b04336 100644 --- a/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java +++ b/src/test/java/org/opensearch/agent/tools/SearchAnomalyDetectorsToolTests.java @@ -172,9 +172,9 @@ public void testRunWithRunningDetectorTrue() throws Exception { ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(String.class); verify(listener, times(1)).onResponse(responseCaptor.capture()); String response = responseCaptor.getValue(); - assertTrue(response.contains(String.format("id=%s", detectorId))); - assertTrue(response.contains(String.format("name=%s", detectorName))); - assertTrue(response.contains(String.format("TotalAnomalyDetectors=%d", hits.length))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(response.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", hits.length))); } @Test @@ -220,9 +220,9 @@ public void testRunWithRunningDetectorUndefined() throws Exception { ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(String.class); verify(listener, times(1)).onResponse(responseCaptor.capture()); String response = responseCaptor.getValue(); - assertTrue(response.contains(String.format("id=%s", detectorId))); - assertTrue(response.contains(String.format("name=%s", detectorName))); - assertTrue(response.contains(String.format("TotalAnomalyDetectors=%d", hits.length))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(response.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", hits.length))); } @Test @@ -248,9 +248,9 @@ public void testRunWithNullRealtimeTask() throws Exception { ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(String.class); verify(listener, times(1)).onResponse(responseCaptor.capture()); String response = responseCaptor.getValue(); - assertTrue(response.contains(String.format("id=%s", detectorId))); - assertTrue(response.contains(String.format("name=%s", detectorName))); - assertTrue(response.contains(String.format("TotalAnomalyDetectors=%d", hits.length))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(response.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", hits.length))); } @Test @@ -275,9 +275,9 @@ public void testRunWithTaskStateCreated() throws Exception { ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(String.class); verify(listener, times(1)).onResponse(responseCaptor.capture()); String response = responseCaptor.getValue(); - assertTrue(response.contains(String.format("id=%s", detectorId))); - assertTrue(response.contains(String.format("name=%s", detectorName))); - assertTrue(response.contains(String.format("TotalAnomalyDetectors=%d", hits.length))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName))); + assertTrue(response.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", hits.length))); } @Test @@ -309,13 +309,13 @@ public void testRunWithTaskStateVariousFailed() throws Exception { ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(String.class); verify(listener, times(1)).onResponse(responseCaptor.capture()); String response = responseCaptor.getValue(); - assertTrue(response.contains(String.format("id=%s", detectorId1))); - assertTrue(response.contains(String.format("name=%s", detectorName1))); - assertTrue(response.contains(String.format("id=%s", detectorId2))); - assertTrue(response.contains(String.format("name=%s", detectorName2))); - assertTrue(response.contains(String.format("id=%s", detectorId3))); - assertTrue(response.contains(String.format("name=%s", detectorName3))); - assertTrue(response.contains(String.format("TotalAnomalyDetectors=%d", hits.length))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId1))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName1))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId2))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName2))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId3))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName3))); + assertTrue(response.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", hits.length))); } @Test @@ -347,11 +347,11 @@ public void testRunWithCombinedDetectorStatesTrue() throws Exception { ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(String.class); verify(listener, times(1)).onResponse(responseCaptor.capture()); String response = responseCaptor.getValue(); - assertTrue(response.contains(String.format("id=%s", detectorId1))); - assertTrue(response.contains(String.format("name=%s", detectorName1))); - assertTrue(response.contains(String.format("id=%s", detectorId3))); - assertTrue(response.contains(String.format("name=%s", detectorName3))); - assertTrue(response.contains(String.format("TotalAnomalyDetectors=%d", 2))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId1))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName1))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId3))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName3))); + assertTrue(response.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 2))); } @Test @@ -414,9 +414,9 @@ public void testRunWithCombinedDetectorStatesMixed() throws Exception { ArgumentCaptor responseCaptor = ArgumentCaptor.forClass(String.class); verify(listener, times(1)).onResponse(responseCaptor.capture()); String response = responseCaptor.getValue(); - assertTrue(response.contains(String.format("id=%s", detectorId1))); - assertTrue(response.contains(String.format("name=%s", detectorName1))); - assertTrue(response.contains(String.format("TotalAnomalyDetectors=%d", 1))); + assertTrue(response.contains(String.format(Locale.ROOT, "id=%s", detectorId1))); + assertTrue(response.contains(String.format(Locale.ROOT, "name=%s", detectorName1))); + assertTrue(response.contains(String.format(Locale.ROOT, "TotalAnomalyDetectors=%d", 1))); } @Test diff --git a/src/test/java/org/opensearch/integTest/SearchAnomalyResultsToolIT.java b/src/test/java/org/opensearch/integTest/SearchAnomalyResultsToolIT.java index 0a9e192e..46234ea6 100644 --- a/src/test/java/org/opensearch/integTest/SearchAnomalyResultsToolIT.java +++ b/src/test/java/org/opensearch/integTest/SearchAnomalyResultsToolIT.java @@ -117,7 +117,10 @@ public void testSearchAnomalyResultsToolInFlowAgent_complexParams() { + "\"realTime\": true, \"anomalyGradeThreshold\": 0, \"sortOrder\": \"asc\"," + "\"sortString\": \"data_start_time\", \"size\": 10, \"startIndex\": 0 }}"; String result = executeAgent(agentId, agentInput); - assertTrue(result.contains(String.format("TotalAnomalyResults=%d", 1))); + assertTrue( + String.format(Locale.ROOT, "total anomaly results is not 1, result: %s", result), + result.contains(String.format(Locale.ROOT, "TotalAnomalyResults=%d", 1)) + ); } @SneakyThrows diff --git a/src/test/java/org/opensearch/integTest/SearchMonitorsToolIT.java b/src/test/java/org/opensearch/integTest/SearchMonitorsToolIT.java index cd3eca09..b0ee3503 100644 --- a/src/test/java/org/opensearch/integTest/SearchMonitorsToolIT.java +++ b/src/test/java/org/opensearch/integTest/SearchMonitorsToolIT.java @@ -9,6 +9,7 @@ import java.nio.file.Files; import java.nio.file.Path; +import java.util.Locale; import org.junit.After; import org.junit.Before; @@ -65,7 +66,7 @@ public void testSearchMonitorsToolInFlowAgent_searchById() { String agentId = createAgent(registerAgentRequestBody); String agentInput = "{\"parameters\":{\"monitorId\": \"" + monitorId + "\"}}"; String result = executeAgent(agentId, agentInput); - assertTrue(result.contains(String.format("name=%s", monitorName))); + assertTrue(result.contains(String.format(Locale.ROOT, "name=%s", monitorName))); assertTrue(result.contains("TotalMonitors=1")); deleteMonitor(monitorId); } @@ -78,7 +79,7 @@ public void testSearchMonitorsToolInFlowAgent_singleMonitor_noFilter() { String agentId = createAgent(registerAgentRequestBody); String agentInput = "{\"parameters\":{}}"; String result = executeAgent(agentId, agentInput); - assertTrue(result.contains(String.format("name=%s", monitorName))); + assertTrue(result.contains(String.format(Locale.ROOT, "name=%s", monitorName))); assertTrue(result.contains("TotalMonitors=1")); deleteMonitor(monitorId); } @@ -101,8 +102,8 @@ public void testSearchMonitorsToolInFlowAgent_multipleMonitors_noFilter() { String agentId = createAgent(registerAgentRequestBody); String agentInput = "{\"parameters\":{}}"; String result = executeAgent(agentId, agentInput); - assertTrue(result.contains(String.format("name=%s", monitorName))); - assertTrue(result.contains(String.format("name=%s", monitorName2))); + assertTrue(result.contains(String.format(Locale.ROOT, "name=%s", monitorName))); + assertTrue(result.contains(String.format(Locale.ROOT, "name=%s", monitorName2))); assertTrue(result.contains("enabled=true")); assertTrue(result.contains("enabled=false")); assertTrue(result.contains("TotalMonitors=2")); @@ -119,8 +120,8 @@ public void testSearchMonitorsToolInFlowAgent_multipleMonitors_filter() { String agentId = createAgent(registerAgentRequestBody); String agentInput = "{\"parameters\":{\"monitorName\": \"" + monitorName + "\"}}"; String result = executeAgent(agentId, agentInput); - assertTrue(result.contains(String.format("name=%s", monitorName))); - assertFalse(result.contains(String.format("name=%s", monitorName2))); + assertTrue(result.contains(String.format(Locale.ROOT, "name=%s", monitorName))); + assertFalse(result.contains(String.format(Locale.ROOT, "name=%s", monitorName2))); assertTrue(result.contains("enabled=true")); assertTrue(result.contains("TotalMonitors=1")); deleteMonitor(monitorId1);