@@ -811,7 +811,11 @@ class MonitorRestApiIT : AlertingRestTestCase() {
811
811
assertEquals(" Delete request not successful" , RestStatus .OK , deleteResponse.restStatus())
812
812
813
813
// Wait 5 seconds for event to be processed and alerts moved
814
- Thread .sleep(5000 )
814
+ OpenSearchTestCase .waitUntil({
815
+ val alerts = searchAlerts(monitor)
816
+ val historyAlerts = searchAlerts(monitor, AlertIndices .ALERT_HISTORY_WRITE_INDEX )
817
+ return @waitUntil (alerts.isEmpty() && historyAlerts.size == 1 )
818
+ }, 5 , TimeUnit .SECONDS )
815
819
816
820
val alerts = searchAlerts(monitor)
817
821
assertEquals(" Active alert was not deleted" , 0 , alerts.size)
@@ -842,7 +846,9 @@ class MonitorRestApiIT : AlertingRestTestCase() {
842
846
assertEquals(" Update request not successful" , RestStatus .OK , updateResponse.restStatus())
843
847
844
848
// Wait 5 seconds for event to be processed and alerts moved
845
- Thread .sleep(5000 )
849
+ OpenSearchTestCase .waitUntil({
850
+ return @waitUntil false
851
+ }, 5 , TimeUnit .SECONDS )
846
852
847
853
val alerts = searchAlerts(monitor)
848
854
assertEquals(" Active alert was not deleted" , 0 , alerts.size)
@@ -870,7 +876,11 @@ class MonitorRestApiIT : AlertingRestTestCase() {
870
876
assertEquals(" Update request not successful" , RestStatus .OK , updateResponse.restStatus())
871
877
872
878
// Wait 5 seconds for event to be processed and alerts moved
873
- Thread .sleep(5000 )
879
+ OpenSearchTestCase .waitUntil({
880
+ val alerts = searchAlerts(monitor)
881
+ val historyAlerts = searchAlerts(monitor, AlertIndices .ALERT_HISTORY_WRITE_INDEX )
882
+ return @waitUntil (alerts.isEmpty() && historyAlerts.size == 1 )
883
+ }, 5 , TimeUnit .SECONDS )
874
884
875
885
val alerts = searchAlerts(monitor)
876
886
assertEquals(" Active alert was not deleted" , 0 , alerts.size)
@@ -956,10 +966,13 @@ class MonitorRestApiIT : AlertingRestTestCase() {
956
966
957
967
fun `test monitor stats when disabling and re-enabling scheduled jobs with existing monitor` () {
958
968
// Enable Monitor jobs
969
+
959
970
enableScheduledJob()
960
971
val monitorId = createMonitor(randomQueryLevelMonitor(enabled = true ), refresh = true ).id
961
972
962
- if (isMultiNode) Thread .sleep(2000 )
973
+ if (isMultiNode) OpenSearchTestCase .waitUntil({
974
+ return @waitUntil false
975
+ }, 2 , TimeUnit .SECONDS )
963
976
var alertingStats = getAlertingStats()
964
977
assertAlertingStatsSweeperEnabled(alertingStats, true )
965
978
assertEquals(" Scheduled job index does not exist" , true , alertingStats[" scheduled_job_index_exists" ])
@@ -992,7 +1005,9 @@ class MonitorRestApiIT : AlertingRestTestCase() {
992
1005
enableScheduledJob()
993
1006
994
1007
// Sleep briefly so sweep can reschedule the Monitor
995
- Thread .sleep(2000 )
1008
+ OpenSearchTestCase .waitUntil({
1009
+ return @waitUntil false
1010
+ }, 2 , TimeUnit .SECONDS )
996
1011
997
1012
alertingStats = getAlertingStats()
998
1013
assertAlertingStatsSweeperEnabled(alertingStats, true )
@@ -1015,10 +1030,13 @@ class MonitorRestApiIT : AlertingRestTestCase() {
1015
1030
1016
1031
fun `test monitor stats jobs` () {
1017
1032
// Enable the Monitor plugin.
1033
+
1018
1034
enableScheduledJob()
1019
1035
createRandomMonitor(refresh = true )
1020
1036
1021
- if (isMultiNode) Thread .sleep(2000 )
1037
+ if (isMultiNode) OpenSearchTestCase .waitUntil({
1038
+ return @waitUntil false
1039
+ }, 2 , TimeUnit .SECONDS )
1022
1040
val responseMap = getAlertingStats()
1023
1041
assertAlertingStatsSweeperEnabled(responseMap, true )
1024
1042
assertEquals(" Scheduled job index does not exist" , true , responseMap[" scheduled_job_index_exists" ])
@@ -1051,7 +1069,9 @@ class MonitorRestApiIT : AlertingRestTestCase() {
1051
1069
enableScheduledJob()
1052
1070
createRandomMonitor(refresh = true )
1053
1071
1054
- if (isMultiNode) Thread .sleep(2000 )
1072
+ if (isMultiNode) OpenSearchTestCase .waitUntil({
1073
+ return @waitUntil false
1074
+ }, 2 , TimeUnit .SECONDS )
1055
1075
val responseMap = getAlertingStats(" /jobs_info" )
1056
1076
assertAlertingStatsSweeperEnabled(responseMap, true )
1057
1077
assertEquals(" Scheduled job index does not exist" , true , responseMap[" scheduled_job_index_exists" ])
0 commit comments