Skip to content

Commit

Permalink
Fix TestLdapSyncMassive
Browse files Browse the repository at this point in the history
A couple of smaller fixes, ported from the master branch.
Intentionally NOT back-porting the assertion of "threads+1"
in test232, as the livesync task is stopped in this version
of the test (at that point).
  • Loading branch information
mederly committed Jul 7, 2022
1 parent 52e4e37 commit 743e98a
Showing 1 changed file with 31 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.testing.story.ldap;


Expand Down Expand Up @@ -53,11 +52,10 @@
* management related to sync (e.g. MID-5099)
*
* @author Radovan Semancik
*
*/
@ContextConfiguration(locations = {"classpath:ctx-story-test-main.xml"})
@ContextConfiguration(locations = { "classpath:ctx-story-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestLdapSyncMassive extends AbstractLdapTest {
public class TestLdapSyncMassive extends AbstractLdapTest {

public static final File TEST_DIR = new File(LDAP_TEST_DIR, "sync-massive");

Expand Down Expand Up @@ -87,7 +85,16 @@ public class TestLdapSyncMassive extends AbstractLdapTest {
private static final Integer TEST_THREADS_RANDOM_START_RANGE = 10;
private static final long PARALLEL_TEST_TIMEOUT = 60000L;

/**
* Hypothesis why we experience three (not only two) connector instances e.g. for test150AddGoblins:
* 1. instance is for main thread when creating goblins
* 2. instance is for some internal connector thread for live sync query (this thread seems to run asynchronously even after sync() returns)
* 3. instance is for worker thread of LiveSync task when it's starting (it does so each second)
*/
private static final int INSTANCES_MAX = 3;

private PrismObject<ResourceType> resourceOpenDj;

private Integer lastSyncToken;
private int threadCountBaseline;

Expand All @@ -110,7 +117,7 @@ protected void startResources() throws Exception {
}

@AfterClass
public static void stopResources() throws Exception {
public static void stopResources() {
openDJController.stop();
}

Expand Down Expand Up @@ -226,10 +233,8 @@ public void test112SyncAddGoods() throws Exception {
displayThen(TEST_NAME);

dumpLdap();

}


/**
* Add "goblin" users, each with an LDAP account.
* We do not really needs them now. But these will make
Expand Down Expand Up @@ -261,24 +266,22 @@ public void test150AddGoblins() throws Exception {
displayThen(TEST_NAME);

dumpLdap();
assertLdapConnectorInstances(1,2);
assertLdapConnectorInstances(1, INSTANCES_MAX);

waitForTaskNextRunAssertSuccess(TASK_LIVE_SYNC_OID, true);

assertLdapConnectorInstances(1,2);
assertLdapConnectorInstances(1, INSTANCES_MAX);
assertSyncTokenIncrement(NUMBER_OF_GOBLINS);
assertThreadCount();

waitForTaskNextRunAssertSuccess(TASK_LIVE_SYNC_OID, true);

assertLdapConnectorInstances(1,2);
assertLdapConnectorInstances(1, INSTANCES_MAX);
assertSyncTokenIncrement(0);
assertThreadCount();

}



private String goblinUsername(int i) {
return String.format("goblin%05d", i);
}
Expand Down Expand Up @@ -435,6 +438,7 @@ public void test232UserRecomputeParallel() throws Exception {
int segmentSize = users.size() / NUMBER_OF_TEST_THREADS;
ParallelTestThread[] threads = multithread(TEST_NAME,
(threadIndex) -> {
login(userAdministrator.clone());
for (int i = segmentSize * threadIndex; i < segmentSize * threadIndex + segmentSize; i++) {
PrismObject<UserType> user = users.get(i);
reconcile(TEST_NAME, user);
Expand All @@ -448,7 +452,7 @@ public void test232UserRecomputeParallel() throws Exception {

// When system is put under load, this means more threads. But not huge number of threads.
assertThreadCount(THREAD_COUNT_TOLERANCE_BIG);
assertLdapConnectorInstances(1,NUMBER_OF_TEST_THREADS);
assertLdapConnectorInstances(1, NUMBER_OF_TEST_THREADS);
}

private void reconcile(final String TEST_NAME, PrismObject<UserType> user) throws CommunicationException, ObjectAlreadyExistsException, ExpressionEvaluationException, PolicyViolationException, SchemaException, SecurityViolationException, ConfigurationException, ObjectNotFoundException {
Expand All @@ -459,7 +463,7 @@ private void reconcile(final String TEST_NAME, PrismObject<UserType> user) throw

// We do not bother to check result. Even though the
// timeout is small, the operation may succeed occasionally.
// This annoying success cout cause the tests to fail.
// This annoying success count cause the tests to fail.
}

private void syncAddAttemptGood(String prefix, int index) throws Exception {
Expand Down Expand Up @@ -494,16 +498,16 @@ private void syncAddAttemptBad(String prefix, int index) throws Exception {

private void addAttemptEntry(String uid, String cn, String sn) throws Exception {
Entry entry = openDJController.addEntry(
"dn: uid="+uid+",ou=People,dc=example,dc=com\n" +
"uid: "+uid+"\n" +
"cn: "+cn+"\n" +
"sn: "+sn+"\n" +
"givenname: "+uid+"\n" +
"objectclass: top\n" +
"objectclass: person\n" +
"objectclass: organizationalPerson\n" +
"objectclass: inetOrgPerson"
);
"dn: uid=" + uid + ",ou=People,dc=example,dc=com\n" +
"uid: " + uid + "\n" +
"cn: " + cn + "\n" +
"sn: " + sn + "\n" +
"givenname: " + uid + "\n" +
"objectclass: top\n" +
"objectclass: person\n" +
"objectclass: organizationalPerson\n" +
"objectclass: inetOrgPerson"
);
display("Added generated entry", entry);
}

Expand All @@ -514,18 +518,13 @@ private void assertThreadCount() {
private void assertThreadCount(int tolerance) {
int currentThreadCount = Thread.activeCount();
if (!isWithinTolerance(threadCountBaseline, currentThreadCount, tolerance)) {
fail("Thread count out of tolerance: "+currentThreadCount+" ("+(currentThreadCount-threadCountBaseline)+")");
fail("Thread count out of tolerance: " + currentThreadCount + " (" + (currentThreadCount - threadCountBaseline) + ")");
}
}

private boolean isWithinTolerance(int baseline, int currentCount, int tolerance) {
if (currentCount > baseline + tolerance) {
return false;
}
if (currentCount < baseline - tolerance) {
return false;
}
return true;
return currentCount <= baseline + tolerance
&& currentCount >= baseline - tolerance;
}

private void assertSyncTokenIncrement(int expectedIncrement) throws ObjectNotFoundException, SchemaException, SecurityViolationException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
Expand All @@ -542,6 +541,4 @@ private void assertSyncTokenIncrement(int expectedIncrement) throws ObjectNotFou
protected void dumpLdap() throws DirectoryException {
display("LDAP server tree", openDJController.dumpTree());
}


}

0 comments on commit 743e98a

Please sign in to comment.