Skip to content

Commit 3cc8bed

Browse files
authored
Fix flaky BindOperationTestCase subtree auth-info tests (#727)
1 parent 8563101 commit 3cc8bed

1 file changed

Lines changed: 37 additions & 4 deletions

File tree

opendj-server-legacy/src/test/java/org/opends/server/core/BindOperationTestCase.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
import org.opends.server.types.Control;
4646
import org.opends.server.types.Operation;
4747
import org.opends.server.types.OperationType;
48+
import org.opends.server.util.TestTimer;
4849
import org.testng.annotations.DataProvider;
4950
import org.testng.annotations.Test;
5051

52+
import static java.util.concurrent.TimeUnit.*;
5153
import static org.assertj.core.api.Assertions.*;
5254
import static org.forgerock.opendj.ldap.ModificationType.*;
5355
import static org.forgerock.opendj.ldap.requests.Requests.*;
@@ -1527,7 +1529,16 @@ public void testSubtreeDeleteClearsAuthInfo()
15271529
};
15281530
assertEquals(LDAPDelete.run(nullPrintStream(), System.err, args), 0);
15291531

1530-
assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN));
1532+
// AuthenticatedUsers is a POST_RESPONSE plugin: the registry is updated
1533+
// after the client already received the response, so poll briefly.
1534+
newAuthInfoTimer().repeatUntilSuccess(new TestTimer.CallableVoid()
1535+
{
1536+
@Override
1537+
public void call() throws Exception
1538+
{
1539+
assertNull(DirectoryServer.getAuthenticatedUsers().get(userDN));
1540+
}
1541+
});
15311542
}
15321543
finally
15331544
{
@@ -1591,16 +1602,38 @@ public void testSubtreeModifyUpdatesAuthInfo()
15911602
};
15921603
assertEquals(LDAPModify.run(nullPrintStream(), System.err, args), 0);
15931604

1594-
DN newUserDN = DN.valueOf("uid=test,ou=users,dc=example,dc=com");
1595-
assertNotNull(DirectoryServer.getAuthenticatedUsers().get(newUserDN));
1596-
assertEquals(DirectoryServer.getAuthenticatedUsers().get(newUserDN).size(), 1);
1605+
final DN newUserDN = DN.valueOf("uid=test,ou=users,dc=example,dc=com");
1606+
// AuthenticatedUsers is a POST_RESPONSE plugin: the registry is updated
1607+
// after the client already received the response, so poll briefly.
1608+
newAuthInfoTimer().repeatUntilSuccess(new TestTimer.CallableVoid()
1609+
{
1610+
@Override
1611+
public void call() throws Exception
1612+
{
1613+
assertNotNull(DirectoryServer.getAuthenticatedUsers().get(newUserDN));
1614+
assertEquals(DirectoryServer.getAuthenticatedUsers().get(newUserDN).size(), 1);
1615+
}
1616+
});
15971617
}
15981618
finally
15991619
{
16001620
TestCaseUtils.clearBackend("userRoot");
16011621
}
16021622
}
16031623

1624+
/**
1625+
* Timer to await the asynchronous {@link AuthenticatedUsers} registry
1626+
* update: it is performed by a POST_RESPONSE plugin, i.e. after the client
1627+
* already received the operation response.
1628+
*/
1629+
private TestTimer newAuthInfoTimer()
1630+
{
1631+
return new TestTimer.Builder()
1632+
.maxSleep(10, SECONDS)
1633+
.sleepTimes(100, MILLISECONDS)
1634+
.toTimer();
1635+
}
1636+
16041637
/**
16051638
* Tests to ensure that the "ignore" password policy state update policy
16061639
* works as expected.

0 commit comments

Comments
 (0)