Fixed CI by making lock acquisition the first operation in the write transaction, followed by a fresh existence check. Added explicit call-order coverage.

This commit is contained in:
Adam Decatur
2026-09-15 16:19:29 -05:00
parent 14ff2ebc64
commit 5320259d29
2 changed files with 5 additions and 7 deletions
@@ -155,11 +155,6 @@ public class IdentityServiceJITProvisioningHandler
private OIDCUserInfo createUserIfNeeded(OIDCUserInfo userInfo)
{
String username = userInfo.username();
if (!userNeedsCreating(userInfo))
{
return userInfo;
}
QName lockQName = QName.createQName(LOCK_NAMESPACE, username.toLowerCase(Locale.ROOT));
jobLockService.getTransactionalLock(lockQName, LOCK_TTL, LOCK_RETRY_WAIT, LOCK_RETRY_COUNT);
if (personService.personExists(username))
@@ -186,7 +186,7 @@ public class IdentityServiceJITProvisioningHandlerUnitTest
public void shouldNotCreateUserWhenItAppearsWhileWaitingForLock()
{
when(clientRegistration.getProviderDetails().getUserInfoEndpoint().getUserNameAttributeName()).thenReturn(PersonClaims.PREFERRED_USERNAME_CLAIM_NAME);
when(personService.personExists(USERNAME)).thenReturn(false, false, true);
when(personService.personExists(USERNAME)).thenReturn(false, true);
when(decodedAccessToken.getClaim(PersonClaims.PREFERRED_USERNAME_CLAIM_NAME)).thenReturn(USERNAME);
jitProvisioningHandler = new IdentityServiceJITProvisioningHandler(identityServiceFacade, personService, transactionService, identityServiceConfig, jobLockService);
@@ -194,7 +194,10 @@ public class IdentityServiceJITProvisioningHandlerUnitTest
assertTrue(result.isPresent());
assertEquals(USERNAME, result.get().username());
verify(jobLockService).getTransactionalLock(any(), anyLong(), anyLong(), anyInt());
InOrder callOrder = inOrder(personService, jobLockService);
callOrder.verify(personService).personExists(USERNAME);
callOrder.verify(jobLockService).getTransactionalLock(any(), anyLong(), anyLong(), anyInt());
callOrder.verify(personService).personExists(USERNAME);
verify(personService, never()).createPerson(any());
}