From 3d663802bb6ed2ebf7482676fe9201c23803bac3 Mon Sep 17 00:00:00 2001 From: Giuseppe Graziano Date: Mon, 28 Oct 2024 11:05:54 +0100 Subject: [PATCH] Fix flaky test for concurrent client creation on H2 database Closes #29290 Signed-off-by: Giuseppe Graziano --- .../admin/concurrency/ConcurrencyTest.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/concurrency/ConcurrencyTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/concurrency/ConcurrencyTest.java index b3f0aaf9ef..5aa8704767 100755 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/concurrency/ConcurrencyTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/admin/concurrency/ConcurrencyTest.java @@ -35,12 +35,14 @@ import jakarta.ws.rs.core.Response; import org.keycloak.representations.idm.UserRepresentation; import org.keycloak.testsuite.admin.ApiUtil; +import org.keycloak.testsuite.model.StoreProvider; import org.keycloak.testsuite.util.UserBuilder; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.IntStream; import org.junit.Ignore; @@ -163,11 +165,18 @@ public class ConcurrencyTest extends AbstractConcurrencyTest { c = realm.clients().get(id).toRepresentation(); assertNotNull(c); - assertTrue("Client " + name + " not found in client list", - realm.clients().findAll().stream() - .map(ClientRepresentation::getClientId) - .filter(Objects::nonNull) - .anyMatch(name::equals)); + + int findAttempts = 1; + if (StoreProvider.getCurrentProvider().equals(StoreProvider.DEFAULT)) { + findAttempts = 5; + } + boolean clientFound = IntStream.range(0, findAttempts) + .anyMatch(i -> realm.clients().findAll().stream() + .map(ClientRepresentation::getClientId) + .filter(Objects::nonNull) + .anyMatch(name::equals)); + + assertTrue("Client " + name + " not found in client list after " + findAttempts + " attempts", clientFound); } } @@ -193,11 +202,18 @@ public class ConcurrencyTest extends AbstractConcurrencyTest { c = client.toRepresentation(); assertNotNull(c); - assertTrue("Client " + name + " not found in client list", - clients.findAll().stream() - .map(ClientRepresentation::getClientId) - .filter(Objects::nonNull) - .anyMatch(name::equals)); + + int findAttempts = 1; + if (StoreProvider.getCurrentProvider().equals(StoreProvider.DEFAULT)) { + findAttempts = 5; + } + boolean clientFound = IntStream.range(0, findAttempts) + .anyMatch(i -> clients.findAll().stream() + .map(ClientRepresentation::getClientId) + .filter(Objects::nonNull) + .anyMatch(name::equals)); + + assertTrue("Client " + name + " not found in client list after " + findAttempts + " attempts", clientFound); client.remove(); try {