Fix flaky test for concurrent client creation on H2 database

Closes #29290

Signed-off-by: Giuseppe Graziano <g.graziano94@gmail.com>
This commit is contained in:
Giuseppe Graziano 2024-10-28 11:05:54 +01:00 committed by Pedro Igor
parent de973de800
commit 3d663802bb

View file

@ -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()
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,12 +202,19 @@ public class ConcurrencyTest extends AbstractConcurrencyTest {
c = client.toRepresentation();
assertNotNull(c);
assertTrue("Client " + name + " not found in client list",
clients.findAll().stream()
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 {
client.toRepresentation();