Skip to content

Commit 37c87d6

Browse files
committed
fixed intermitent failures for delayed alert fire
1 parent be5c438 commit 37c87d6

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

integration-tests/src/test/java/oracle/kubernetes/operator/ItMonitoringExporter.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -851,13 +851,10 @@ private void fireAlert() throws Exception {
851851

852852
TestUtils.checkPodReady("domain1-admin-server", "default");
853853
TestUtils.checkPodReady("domain1-managed-server-1", "default");
854-
//sleep for 2 min to fire alert
855-
Thread.sleep(120000);
854+
856855
String webhookPod = getPodName("webhook", "webhook");
857856
String command = "kubectl -n webhook logs " + webhookPod;
858-
ExecResult webhookResult = TestUtils.exec(command);
859-
logger.info(" webhook log " + webhookResult.stdout());
860-
assertTrue( webhookResult.stdout().contains("Some WLS cluster has only one running server for more than 1 minutes"));
857+
ExecResult webhookResult = TestUtils.checkAnyCmdInLoop(command, "Some WLS cluster has only one running server for more than 1 minutes");
861858
}
862859

863860
private static String getPodName(String app, String namespace) throws Exception {

integration-tests/src/test/java/oracle/kubernetes/operator/utils/TestUtils.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,49 @@ private static KeyStore createKeyStore(Operator operator) throws Exception {
11631163
return myKeyStore;
11641164
}
11651165

1166+
/**
1167+
*
1168+
* @param cmd command to run in the loop
1169+
* @param matchStr expected string to match in the output
1170+
* @return ExecResult object containing command output info
1171+
* @throws Exception exception if fails to execute
1172+
*/
1173+
public static ExecResult checkAnyCmdInLoop(String cmd, String matchStr)
1174+
throws Exception {
1175+
int i = 0;
1176+
ExecResult result = null;
1177+
while (i < BaseTest.getMaxIterationsPod()) {
1178+
result = ExecCommand.exec(cmd);
1179+
1180+
if (result.exitValue() != 0
1181+
|| (result.exitValue() == 0 && !result.stdout().contains(matchStr))) {
1182+
logger.info("Output for " + cmd + "\n" + result.stdout() + "\n " + result.stderr());
1183+
// check for last iteration
1184+
if (i == (BaseTest.getMaxIterationsPod() - 1)) {
1185+
throw new RuntimeException(
1186+
"FAILURE: expected output " + matchStr + " from command " + cmd + " is not receieved, exiting!");
1187+
}
1188+
logger.info(
1189+
"did not receive the expected output "
1190+
+ matchStr
1191+
+ "from command " + cmd + " Ite ["
1192+
+ i
1193+
+ "/"
1194+
+ BaseTest.getMaxIterationsPod()
1195+
+ "], sleeping "
1196+
+ BaseTest.getWaitTimePod()
1197+
+ " seconds more");
1198+
1199+
Thread.sleep(BaseTest.getWaitTimePod() * 1000);
1200+
i++;
1201+
} else {
1202+
logger.info("Command " + cmd + " is successful");
1203+
break;
1204+
}
1205+
}
1206+
return result;
1207+
}
1208+
11661209
public static void checkCmdInLoop(String cmd, String matchStr, String k8sObjName)
11671210
throws Exception {
11681211
int i = 0;

0 commit comments

Comments
 (0)