From e750b44e9dec7e88db4f6cf1fd699a913d97a0ff Mon Sep 17 00:00:00 2001 From: Martin Kanis Date: Wed, 7 Aug 2024 13:15:26 +0200 Subject: [PATCH] Flaky test: org.keycloak.testsuite.model.DBLockTest#testTwoLocksCurrently Closes #25794 Signed-off-by: Martin Kanis --- .../org/keycloak/testsuite/model/DBLockTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/testsuite/model/src/test/java/org/keycloak/testsuite/model/DBLockTest.java b/testsuite/model/src/test/java/org/keycloak/testsuite/model/DBLockTest.java index 65da7705f4..9c7e383f1b 100644 --- a/testsuite/model/src/test/java/org/keycloak/testsuite/model/DBLockTest.java +++ b/testsuite/model/src/test/java/org/keycloak/testsuite/model/DBLockTest.java @@ -20,6 +20,8 @@ package org.keycloak.testsuite.model; import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.IntStream; + import org.jboss.logging.Logger; import org.junit.Assert; import org.junit.Before; @@ -188,19 +190,19 @@ public class DBLockTest extends KeycloakModelTest { for (int i = 0; i < 2; i++) { final DBLockProvider.Namespace lock = (i % 2 == 0)? lock1 : lock2; Thread thread = new Thread(() -> { - for (int j = 0; j < ITERATIONS_PER_THREAD_LONG; j++) { + IntStream.range(0, ITERATIONS_PER_THREAD_LONG).parallel().forEach(j -> { try { KeycloakModelUtils.runJobInTransaction(sessionFactory, session1 -> lock(session1, lock, semaphore)); } catch (RuntimeException e) { semaphore.setException(e); } - } + }); }); threads.add(thread); } - for (Thread thread : threads) { - thread.start(); - } + + threads.parallelStream().forEach(Thread::start); + for (Thread thread : threads) { try { thread.join();