Skip to content

Commit

Permalink
Fix flaky ITs (#332) (#333)
Browse files Browse the repository at this point in the history
* Fix flaky ITs



* fix compilation error



---------


(cherry picked from commit 30bd989)

Signed-off-by: zane-neo <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 571a76e commit 2796207
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ public void testRunWithRunningDetectorTrue() throws Exception {
ArgumentCaptor<String> 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
Expand Down Expand Up @@ -220,9 +220,9 @@ public void testRunWithRunningDetectorUndefined() throws Exception {
ArgumentCaptor<String> 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
Expand All @@ -248,9 +248,9 @@ public void testRunWithNullRealtimeTask() throws Exception {
ArgumentCaptor<String> 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
Expand All @@ -275,9 +275,9 @@ public void testRunWithTaskStateCreated() throws Exception {
ArgumentCaptor<String> 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
Expand Down Expand Up @@ -309,13 +309,13 @@ public void testRunWithTaskStateVariousFailed() throws Exception {
ArgumentCaptor<String> 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
Expand Down Expand Up @@ -347,11 +347,11 @@ public void testRunWithCombinedDetectorStatesTrue() throws Exception {
ArgumentCaptor<String> 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
Expand Down Expand Up @@ -414,9 +414,9 @@ public void testRunWithCombinedDetectorStatesMixed() throws Exception {
ArgumentCaptor<String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/org/opensearch/integTest/SearchMonitorsToolIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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"));
Expand All @@ -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);
Expand Down

0 comments on commit 2796207

Please sign in to comment.