Skip to content

Commit c9d0697

Browse files
authored
Improve test verification (#1777)
* Improve test verification * Fail application availability check early * Address a review comment
1 parent 291a16c commit c9d0697

File tree

4 files changed

+51
-12
lines changed

4 files changed

+51
-12
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItMiiDomain.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public void testPatchAppV2() {
410410
} catch (InterruptedException ie) {
411411
// do nothing
412412
}
413-
413+
414414
// check the application availability data that we have collected, and see if
415415
// the application has been available all the time since the beginning of this test method
416416
logger.info("Verify that V2 application was available when domain {0} was being patched with image {1}",
@@ -1045,7 +1045,7 @@ private static void collectAppAvaiability(
10451045
String appPath
10461046
) {
10471047
boolean v2AppAvailable = false;
1048-
1048+
10491049
// Access the pod periodically to check application's availability across the duration
10501050
// of patching the domain with newer version of the application.
10511051
while (!v2AppAvailable) {
@@ -1074,6 +1074,7 @@ private static void collectAppAvaiability(
10741074

10751075
if (count == 0) {
10761076
logger.info("XXXXXXXXXXX: application not available XXXXXXXX");
1077+
break;
10771078
} else {
10781079
logger.fine("YYYYYYYYYYY: application available YYYYYYYY count = " + count);
10791080
}

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItOperatorRestartWhenPodRoll.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
import static oracle.weblogic.kubernetes.actions.TestActions.deletePod;
3535
import static oracle.weblogic.kubernetes.actions.TestActions.getOperatorPodName;
3636
import static oracle.weblogic.kubernetes.actions.TestActions.getPodCreationTimestamp;
37-
import static oracle.weblogic.kubernetes.assertions.TestAssertions.operatorIsReady;
37+
import static oracle.weblogic.kubernetes.assertions.TestAssertions.isOperatorPodRestarted;
3838
import static oracle.weblogic.kubernetes.assertions.TestAssertions.verifyRollingRestartOccurred;
39-
import static oracle.weblogic.kubernetes.assertions.impl.Kubernetes.isPodRestarted;
4039
import static oracle.weblogic.kubernetes.utils.CommonMiiTestUtils.createMiiDomainAndVerify;
4140
import static oracle.weblogic.kubernetes.utils.CommonPatchTestUtils.checkPodRestartVersionUpdated;
4241
import static oracle.weblogic.kubernetes.utils.CommonTestUtils.createSecretWithUsernamePassword;
@@ -235,18 +234,14 @@ private void restartOperatorAndVerify() {
235234
opNamespace,
236235
condition.getElapsedTimeInMS(),
237236
condition.getRemainingTimeInMS()))
238-
.until(assertDoesNotThrow(() -> operatorIsReady(opNamespace),
239-
"operatorIsReady failed with ApiException"));
237+
.until(assertDoesNotThrow(() -> isOperatorPodRestarted(opNamespace, opPodCreationTime),
238+
"Failed to check if the operator is restarted with ApiException"));
240239

241-
String opPodNameNew =
240+
String opPodNameNew =
242241
assertDoesNotThrow(() -> getOperatorPodName(TestConstants.OPERATOR_RELEASE_NAME, opNamespace),
243-
"Failed to get the name of the operator pod");
242+
"Failed to get the name of the operator pod");
244243

245244
assertFalse(opPodNameNew.equals(opPodName),
246245
"The operator names before and after a restart should be different");
247-
248-
assertTrue(assertDoesNotThrow(() -> isPodRestarted(opPodNameNew, opNamespace, opPodCreationTime),
249-
"Failed to check the operator for its new creation time with ApiException"),
250-
"Operator restart failed");
251246
}
252247
}

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/TestAssertions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,22 @@ public static Callable<Boolean> isPodRestarted(
446446
};
447447
}
448448

449+
/**
450+
* Check if the oeprator pod in a given namespace is restarted based on podCreationTimestamp.
451+
*
452+
* @param namespace in which the pod is running
453+
* @param timestamp the initial podCreationTimestamp
454+
* @return true if the pod new timestamp is not equal to initial PodCreationTimestamp otherwise false
455+
*/
456+
public static Callable<Boolean> isOperatorPodRestarted(
457+
String namespace,
458+
DateTime timestamp
459+
) {
460+
return () -> {
461+
return Kubernetes.isOperatorPodRestarted(namespace, timestamp);
462+
};
463+
}
464+
449465
/**
450466
* Verify the pod state is not changed.
451467
*

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/assertions/impl/Kubernetes.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,4 +776,31 @@ public static void copyFileToPod(String namespace,
776776
Copy copy = new Copy(apiClient);
777777
copy.copyFileToPod(namespace, pod, container, srcPath, destPath);
778778
}
779+
780+
/**
781+
* Check if the operator pod in the given namespace is restarted based on podCreationTimestamp.
782+
*
783+
* @param namespace in which the operator pod is running
784+
* @param timestamp the initial podCreationTimestamp
785+
* @return true if the pod's creation timestamp is later than the initial PodCreationTimestamp
786+
* @throws ApiException when query fails
787+
*/
788+
public static Boolean isOperatorPodRestarted(String namespace, DateTime timestamp) throws ApiException {
789+
String labelSelector = String.format("weblogic.operatorName in (%s)", namespace);
790+
V1Pod pod = getPod(namespace, labelSelector, "weblogic-operator-");
791+
if (pod != null) {
792+
// get the podCondition with the 'Ready' type field
793+
V1PodCondition v1PodReadyCondition = pod.getStatus().getConditions().stream()
794+
.filter(v1PodCondition -> "Ready".equals(v1PodCondition.getType()))
795+
.findAny()
796+
.orElse(null);
797+
798+
if (v1PodReadyCondition != null
799+
&& v1PodReadyCondition.getStatus().equalsIgnoreCase("true")) {
800+
String podName = pod.getMetadata().getName();
801+
return isPodRestarted(podName, namespace, timestamp);
802+
}
803+
}
804+
return false;
805+
}
779806
}

0 commit comments

Comments
 (0)