From 838764ba5a6ddffa42ed9e79cb4908395950495b Mon Sep 17 00:00:00 2001 From: mposolda Date: Mon, 22 Feb 2016 12:04:27 +0100 Subject: [PATCH] Fix SyncFederationTest to work with MSSQL and envs with slower databases --- .../federation/sync/SyncFederationTest.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/testsuite/integration/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java b/testsuite/integration/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java index f3e2ec0b15..84a901a171 100644 --- a/testsuite/integration/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java +++ b/testsuite/integration/src/test/java/org/keycloak/testsuite/federation/sync/SyncFederationTest.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import org.jboss.logging.Logger; import org.junit.Assert; import org.junit.ClassRule; import org.junit.FixMethodOrder; @@ -47,6 +48,8 @@ import org.keycloak.timer.TimerProvider; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class SyncFederationTest { + private static final Logger log = Logger.getLogger(SyncFederationTest.class); + private static UserFederationProviderModel dummyModel = null; @ClassRule @@ -87,16 +90,29 @@ public class SyncFederationTest { // Cancel timer RealmModel appRealm = session.realms().getRealmByName("test"); usersSyncManager.notifyToRefreshPeriodicSync(session, appRealm, dummyModel, true); + log.infof("Notified sync manager about cancel periodic sync"); - // Assert that DummyUserFederationProviderFactory.syncChangedUsers was invoked + // This sync is here just to ensure that we have lock (doublecheck that periodic sync, which was possibly triggered before canceling timer is finished too) + while (true) { + UserFederationSyncResult result = usersSyncManager.syncChangedUsers(session.getKeycloakSessionFactory(), appRealm.getId(), dummyModel); + if (result.isIgnored()) { + log.infof("Still waiting for lock before periodic sync is finished", result.toString()); + sleep(1000); + } else { + break; + } + } + + // Assert that DummyUserFederationProviderFactory.syncChangedUsers was invoked at least 2 times (once periodically and once for us) int newChanged = dummyFedFactory.getChangedSyncCounter(); Assert.assertEquals(full, dummyFedFactory.getFullSyncCounter()); - Assert.assertTrue(newChanged > changed); + Assert.assertTrue("Assertion failed. newChanged=" + newChanged + ", changed=" + changed, newChanged > (changed + 1)); // Assert that dummy provider won't be invoked anymore sleep(1800); Assert.assertEquals(full, dummyFedFactory.getFullSyncCounter()); - Assert.assertEquals(newChanged, dummyFedFactory.getChangedSyncCounter()); + int newestChanged = dummyFedFactory.getChangedSyncCounter(); + Assert.assertEquals("Assertion failed. newChanged=" + newChanged + ", newestChanged=" + newestChanged, newChanged, newestChanged); } finally { keycloakRule.stopSession(session, true); }