Skip to content

Commit

Permalink
testing: Introduced TaskUpdatedListener and use it in few test places
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Oct 27, 2021
1 parent c473d18 commit aac7d9f
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public abstract class AbstractSynchronizationStoryTest extends AbstractInitializ
private static final Date ACCOUNT_MANCOMB_VALID_TO_DATE = MiscUtil.asDate(2066, 5, 4, 3, 2, 1);

private static final String ACCOUNT_PROTECTED_SYSTEM = "system";
// Intetionally null
private static final String RESOURCE_DUMMY_DEFAULT_NAME = null;

protected static String userWallyOid;

Expand Down Expand Up @@ -247,8 +249,7 @@ public void test220AddDummyBlueAccountWally() throws Exception {
// Make sure that the "kickback" sync cycle of the other resource runs to completion
// We want to check the state after it gets stable
// and it could spoil the next test
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncActivityCompleted(RESOURCE_DUMMY_GREEN_NAME, RESOURCE_DUMMY_BLUE_NAME);

then();
dumpSyncTaskTree(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME), result);
Expand Down Expand Up @@ -302,8 +303,7 @@ public void test315AddDummyBlueAccountMancomb() throws Exception {
// Make sure that the "kickback" sync cycle of the other resource runs to completion
// We want to check the state after it gets stable
// and it could spoil the next test
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncActivityCompleted(RESOURCE_DUMMY_GREEN_NAME, RESOURCE_DUMMY_BLUE_NAME);

then();
// The checks are simplified here because the developer has a lazy mood :-)
Expand Down Expand Up @@ -376,9 +376,7 @@ public void test360ModifyUserAddDummyDefaultAccount() throws Exception {
dumpSyncTaskTree(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME), result);

// Make sure we have steady state
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject());
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));
waitForSyncActivityCompleted(RESOURCE_DUMMY_DEFAULT_NAME, RESOURCE_DUMMY_GREEN_NAME, RESOURCE_DUMMY_BLUE_NAME);

PrismObject<ShadowType> accountWallyDefault = checkWallyAccount(getDummyResourceObject(), getDummyResource(),
"default", "Wally Feed");
Expand Down Expand Up @@ -430,10 +428,9 @@ public void test370ModifyDummyGreenAccountWally() throws Exception {
// Make sure that the "kickback" sync cycle of the other resource runs to completion
// We want to check the state after it gets stable
// and it could spoil the next test
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));

// Make sure we have steady state
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject());
waitForSyncActivityCompleted(RESOURCE_DUMMY_DEFAULT_NAME, RESOURCE_DUMMY_GREEN_NAME, RESOURCE_DUMMY_BLUE_NAME);

then();
dumpSyncTaskTree(getDummyResourceObject(), result);
Expand Down Expand Up @@ -501,9 +498,9 @@ public void test380ModifyUserWallyFullName() throws Exception {
modifyUserReplace(userWallyOid, UserType.F_FULL_NAME, task, result, PrismTestUtil.createPolyString("Bloodnose"));

// Wait for sync tasks to pick up the change and have some chance to screw things
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject());
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));

waitForSyncActivityCompleted(RESOURCE_DUMMY_DEFAULT_NAME, RESOURCE_DUMMY_GREEN_NAME, RESOURCE_DUMMY_BLUE_NAME);


// Run green recon twice here. If the recon already searched for current state of the
// wally account, the old value ("Wally B. Feed") is stored in the memory. Even if we rewrite
Expand Down Expand Up @@ -565,9 +562,8 @@ public void test382ModifyUserWallyLocality() throws Exception {
modifyUserReplace(userWallyOid, UserType.F_LOCALITY, task, result, PrismTestUtil.createPolyString("Plunder island"));

// Wait for sync tasks to pick up the change and have some chance to screw things
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject());
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));
waitForSyncActivityCompleted(RESOURCE_DUMMY_DEFAULT_NAME, RESOURCE_DUMMY_GREEN_NAME, RESOURCE_DUMMY_BLUE_NAME);


// Run green recon twice here. If the recon already searched for current state of the
// wally account, the old value is stored in the memory. Even if we rewrite
Expand Down Expand Up @@ -639,9 +635,8 @@ public void test400DeleteDummyDefaultAccount() throws Exception {
displayValue("Dummy (default) resource", getDummyResource().debugDump());

// Make sure we have steady state
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject());
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));
waitForSyncActivityCompleted(RESOURCE_DUMMY_DEFAULT_NAME, RESOURCE_DUMMY_GREEN_NAME, RESOURCE_DUMMY_BLUE_NAME);


then();
dumpSyncTaskTree(getDummyResourceObject(), result);
Expand Down Expand Up @@ -699,9 +694,9 @@ public void test410DeleteDummyGreenAccount() throws Exception {
getDummyResource(RESOURCE_DUMMY_GREEN_NAME).deleteAccountByName(ACCOUNT_WALLY_DUMMY_USERNAME);

// Make sure we have steady state
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject());
OperationResult takResultBlue = waitForSyncTaskNextRun(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
waitForSyncTaskNextRunAssertSuccess(getDummyResourceObject(RESOURCE_DUMMY_GREEN_NAME));
var syncWaiter = new SyncWaiter();
OperationResult takResultBlue = syncWaiter.waitForSyncActivityCompleted(getDummyResourceObject(RESOURCE_DUMMY_BLUE_NAME));
syncWaiter.waitForSync(RESOURCE_DUMMY_DEFAULT_NAME, RESOURCE_DUMMY_GREEN_NAME);

then();
dumpSyncTaskTree(getDummyResourceObject(), result);
Expand Down Expand Up @@ -758,11 +753,11 @@ public void test410DeleteDummyGreenAccount() throws Exception {
if (takResultBlue.getStatus() == OperationResultStatus.PARTIAL_ERROR) {
// Blue resource recon may fail. The user may be deleted before the blue
// recon task finishes. If the result (user, accounts) is OK then tolerate this error.
} else {
TestUtil.assertSuccess("Blue resource synchronization has failed", takResultBlue);
} else if (isError(takResultBlue, true)) {
assert false : "Blue resource synchronization has failed";
}
} else {
TestUtil.assertSuccess("Blue resource synchronization has failed", takResultBlue);
} else if (isError(takResultBlue, true)) {
assert false : "Blue resource synchronization has failed";
}

// notifications
Expand Down Expand Up @@ -945,8 +940,39 @@ protected void waitForSyncTaskStart(PrismObject<ResourceType> resource) throws E
waitForTaskStart(getSyncTaskOid(resource), false, getWaitTimeout());
}

protected class SyncWaiter {

private final long afterTime = System.currentTimeMillis();

public SyncWaiter waitForSync(PrismObject<ResourceType> resource) throws CommonException {
waitForSyncActivityCompleted(resource);
return this;
}

public SyncWaiter waitForSync(String... names) throws CommonException {
for (String name : names) {
waitForSyncActivityCompleted(getDummyResourceObject(name));
}
return this;
}


public OperationResult waitForSyncActivityCompleted(PrismObject<ResourceType> resource) throws CommonException {
return waitForTaskActivityCompleted(getSyncTaskOid(resource), afterTime, createOperationResult("wait"), getWaitTimeout());
}
}

protected OperationResult waitForSyncTaskNextRunAssertSuccess(PrismObject<ResourceType> resource) throws Exception {
return waitForTaskNextRunAssertSuccess(getSyncTaskOid(resource), false, getWaitTimeout());
String taskOid = getSyncTaskOid(resource);
var taskResult = waitForSyncTaskNextRun(resource);
if (isError(taskResult, false)) {
assert false : "Error in task " + taskOid + ": " + TestUtil.getErrorMessage(taskResult) + "\n\n" + taskResult.debugDump();
}
return taskResult;
}

protected void waitForSyncActivityCompleted(String... resourceNames) throws CommonException {
new SyncWaiter().waitForSync(resourceNames);
}

protected void dumpSyncTaskTree(PrismObject<ResourceType> resource, OperationResult result)
Expand All @@ -956,7 +982,7 @@ protected void dumpSyncTaskTree(PrismObject<ResourceType> resource, OperationRes
}

protected OperationResult waitForSyncTaskNextRun(PrismObject<ResourceType> resource) throws Exception {
return waitForTaskNextRun(getSyncTaskOid(resource), false, getWaitTimeout());
return waitForTaskActivityCompleted(getSyncTaskOid(resource), System.currentTimeMillis(), createOperationResult("wait"), getWaitTimeout());
}

private PrismObject<ShadowType> checkWallyAccount(PrismObject<ResourceType> resource, DummyResource dummy, String resourceDesc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;

/**
Expand Down Expand Up @@ -74,16 +73,4 @@ protected String getSyncTaskOid(PrismObject<ResourceType> resource) {
}
}

@Override
protected OperationResult waitForSyncTaskNextRunAssertSuccess(PrismObject<ResourceType> resource) throws Exception {
OperationResult result = waitForTaskTreeNextFinishedRun(getSyncTaskOid(resource), getWaitTimeout());
TestUtil.assertSuccess(result);
return result;
}

@Override
protected OperationResult waitForSyncTaskNextRun(PrismObject<ResourceType> resource) throws Exception {
return waitForTaskTreeNextFinishedRun(getSyncTaskOid(resource), getWaitTimeout());
}

}

0 comments on commit aac7d9f

Please sign in to comment.