From 8f1234881de5353891f8220d732ec134f17f5030 Mon Sep 17 00:00:00 2001 From: Steven Hawkins Date: Wed, 18 Oct 2023 02:55:31 -0400 Subject: [PATCH] test: eliminates some possible timing issues with watched secrets tests (#23975) closes #23940 --- .../integration/WatchedSecretsTest.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/operator/src/test/java/org/keycloak/operator/testsuite/integration/WatchedSecretsTest.java b/operator/src/test/java/org/keycloak/operator/testsuite/integration/WatchedSecretsTest.java index 866df23473..46d4505471 100644 --- a/operator/src/test/java/org/keycloak/operator/testsuite/integration/WatchedSecretsTest.java +++ b/operator/src/test/java/org/keycloak/operator/testsuite/integration/WatchedSecretsTest.java @@ -37,8 +37,12 @@ import java.util.Base64; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentSkipListSet; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.Function; +import java.util.concurrent.TimeoutException; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; @@ -168,12 +172,33 @@ public class WatchedSecretsTest extends BaseOperatorTest { var toBeRestarted = crsToBeRestarted.stream().collect(Collectors.toMap(Function.identity(), k -> getStatefulSet(k).getStatus().getUpdateRevision())); var notToBeRestarted = crsNotToBeRestarted.stream().collect(Collectors.toMap(Function.identity(), k -> getStatefulSet(k).getStatus().getUpdateRevision())); + CompletableFuture restartsCompleted = null; + ConcurrentSkipListSet names = new ConcurrentSkipListSet<>(crsToBeRestarted.stream().map(k -> k.getMetadata().getName()).collect(Collectors.toSet())); + if (restartExpected) { + restartsCompleted = k8sclient.resources(Keycloak.class).informOnCondition(keycloaks -> { + for (Keycloak kc : keycloaks) { + if (!names.contains(kc.getMetadata().getName())) { + continue; + } + try { + assertKeycloakStatusCondition(kc.getStatus(), KeycloakStatusCondition.ROLLING_UPDATE, true, null, null); + names.remove(kc.getMetadata().getName()); + } catch (Throwable e) { + // not rolling + } + } + return names.isEmpty(); + }); + } + action.run(); - if (restartExpected) { - // this depends on the restart taking long enough to detect after the action is run - // we may want to switch to using an informer that runs before the action - assertRollingUpdate(crsToBeRestarted, true); + if (restartsCompleted != null) { + try { + restartsCompleted.get(5, TimeUnit.MINUTES); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + throw new RuntimeException(names + " did not restart before an exception occurred", e); + } } Set allCrs = new HashSet<>(crsToBeRestarted);