Skip to content

Commit

Permalink
Fixing race conditions in TestUuid
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 12, 2016
1 parent a965457 commit 583cb26
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Expand Up @@ -35,6 +35,7 @@
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import com.evolveum.icf.dummy.resource.BreakMode;
Expand Down Expand Up @@ -82,6 +83,7 @@
*
*/
@ContextConfiguration(locations = {"classpath:ctx-model-intest-test-main.xml"})
@Listeners({ com.evolveum.midpoint.tools.testng.AlphabeticalMethodInterceptor.class })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public class TestUuid extends AbstractInitializedModelIntegrationTest {

Expand Down Expand Up @@ -208,14 +210,16 @@ public void test210ReconcileDummyUuidAddAugustus() throws Exception {
rememberShadowFetchOperationCount();
reconciliationTaskResultListener.clear();

Task taskBefore = taskManager.getTask(TASK_RECONCILE_DUMMY_UUID_OID, result);

// WHEN
TestUtil.displayWhen(TEST_NAME);
restartTask(TASK_RECONCILE_DUMMY_UUID_OID);

// THEN
TestUtil.displayThen(TEST_NAME);

waitForTaskNextRunAssertSuccess(TASK_RECONCILE_DUMMY_UUID_OID, true);
waitForTaskNextRunAssertSuccess(taskBefore, true);

// THEN
TestUtil.displayThen(TEST_NAME);
Expand Down Expand Up @@ -279,6 +283,8 @@ public void test220ReconcileDummyUuidDeleteAddAugustus() throws Exception {

display("Old shadow OID", augustusShadowOid);
display("Account ID "+ oldAccount.getId() + " -> " + account.getId());

Task taskBefore = taskManager.getTask(TASK_RECONCILE_DUMMY_UUID_OID, result);

dummyResource.purgeScriptHistory();
dummyAuditService.clear();
Expand All @@ -292,7 +298,7 @@ public void test220ReconcileDummyUuidDeleteAddAugustus() throws Exception {
// THEN
TestUtil.displayThen(TEST_NAME);

waitForTaskNextRunAssertSuccess(TASK_RECONCILE_DUMMY_UUID_OID, true);
waitForTaskNextRunAssertSuccess(taskBefore, true);

// THEN
TestUtil.displayThen(TEST_NAME);
Expand Down Expand Up @@ -358,6 +364,8 @@ public void test230ReconcileDummyUuidDeleteAugustusAddAugustina() throws Excepti

display("Old shadow OID", augustusShadowOid);
display("Account ID "+ oldAccount.getId() + " -> " + account.getId());

Task taskBefore = taskManager.getTask(TASK_RECONCILE_DUMMY_UUID_OID, result);

dummyResource.purgeScriptHistory();
dummyAuditService.clear();
Expand All @@ -371,7 +379,7 @@ public void test230ReconcileDummyUuidDeleteAugustusAddAugustina() throws Excepti
// THEN
TestUtil.displayThen(TEST_NAME);

waitForTaskNextRunAssertSuccess(TASK_RECONCILE_DUMMY_UUID_OID, true);
waitForTaskNextRunAssertSuccess(taskBefore, true);

// THEN
TestUtil.displayThen(TEST_NAME);
Expand Down
Expand Up @@ -1958,6 +1958,10 @@ protected OperationResult waitForTaskNextRunAssertSuccess(String taskOid, boolea
return waitForTaskNextRunAssertSuccess(taskOid, checkSubresult, DEFAULT_TASK_WAIT_TIMEOUT);
}

protected OperationResult waitForTaskNextRunAssertSuccess(Task origTask, boolean checkSubresult) throws Exception {
return waitForTaskNextRunAssertSuccess(origTask, checkSubresult, DEFAULT_TASK_WAIT_TIMEOUT);
}

protected OperationResult waitForTaskNextRunAssertSuccess(final String taskOid, final boolean checkSubresult, final int timeout) throws Exception {
OperationResult taskResult = waitForTaskNextRun(taskOid, checkSubresult, timeout);
if (isError(taskResult, checkSubresult)) {
Expand All @@ -1966,16 +1970,33 @@ protected OperationResult waitForTaskNextRunAssertSuccess(final String taskOid,
return taskResult;
}

protected OperationResult waitForTaskNextRunAssertSuccess(Task origTask, final boolean checkSubresult, final int timeout) throws Exception {
OperationResult taskResult = waitForTaskNextRun(origTask, checkSubresult, timeout);
if (isError(taskResult, checkSubresult)) {
assert false : "Error in task "+origTask+": "+TestUtil.getErrorMessage(taskResult)+"\n\n"+taskResult.debugDump();
}
return taskResult;
}

protected OperationResult waitForTaskNextRun(final String taskOid, final boolean checkSubresult, final int timeout) throws Exception {
final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class+".waitForTaskNextRun");
Task origTask = taskManager.getTask(taskOid, waitResult);
return waitForTaskNextRun(origTask, checkSubresult, timeout, waitResult);
}

protected OperationResult waitForTaskNextRun(final Task origTask, final boolean checkSubresult, final int timeout) throws Exception {
final OperationResult waitResult = new OperationResult(AbstractIntegrationTest.class+".waitForTaskNextRun");
return waitForTaskNextRun(origTask, checkSubresult, timeout, waitResult);
}

protected OperationResult waitForTaskNextRun(final Task origTask, final boolean checkSubresult, final int timeout, final OperationResult waitResult) throws Exception {
final Long origLastRunStartTimestamp = origTask.getLastRunStartTimestamp();
final Long origLastRunFinishTimestamp = origTask.getLastRunFinishTimestamp();
final Holder<OperationResult> taskResultHolder = new Holder<>();
Checker checker = new Checker() {
@Override
public boolean check() throws Exception {
Task freshTask = taskManager.getTask(taskOid, waitResult);
Task freshTask = taskManager.getTask(origTask.getOid(), waitResult);
OperationResult taskResult = freshTask.getResult();
// display("Times", longTimeToString(origLastRunStartTimestamp) + "-" + longTimeToString(origLastRunStartTimestamp)
// + " : " + longTimeToString(freshTask.getLastRunStartTimestamp()) + "-" + longTimeToString(freshTask.getLastRunFinishTimestamp()));
Expand All @@ -2000,11 +2021,11 @@ public boolean check() throws Exception {
@Override
public void timeout() {
try {
Task freshTask = taskManager.getTask(taskOid, waitResult);
Task freshTask = taskManager.getTask(origTask.getOid(), waitResult);
OperationResult result = freshTask.getResult();
LOGGER.debug("Timed-out task:\n{}", freshTask.debugDump());
display("Times", "origLastRunStartTimestamp="+longTimeToString(origLastRunStartTimestamp)
+ ", origLastRunStartTimestamp=" + longTimeToString(origLastRunStartTimestamp)
+ ", origLastRunFinishTimestamp=" + longTimeToString(origLastRunFinishTimestamp)
+ ", freshTask.getLastRunStartTimestamp()=" + longTimeToString(freshTask.getLastRunStartTimestamp())
+ ", freshTask.getLastRunFinishTimestamp()=" + longTimeToString(freshTask.getLastRunFinishTimestamp()));
assert false : "Timeout ("+timeout+") while waiting for "+freshTask+" next run. Last result "+result;
Expand All @@ -2015,12 +2036,12 @@ public void timeout() {
}
}
};
IntegrationTestTools.waitFor("Waiting for task " + taskOid + " next run", checker, timeout, DEFAULT_TASK_SLEEP_TIME);
IntegrationTestTools.waitFor("Waiting for task " + origTask + " next run", checker, timeout, DEFAULT_TASK_SLEEP_TIME);

Task freshTask = taskManager.getTask(taskOid, waitResult);
Task freshTask = taskManager.getTask(origTask.getOid(), waitResult);
LOGGER.debug("Final task:\n{}", freshTask.debugDump());
display("Times", "origLastRunStartTimestamp="+longTimeToString(origLastRunStartTimestamp)
+ ", origLastRunStartTimestamp=" + longTimeToString(origLastRunStartTimestamp)
+ ", origLastRunFinishTimestamp=" + longTimeToString(origLastRunFinishTimestamp)
+ ", freshTask.getLastRunStartTimestamp()=" + longTimeToString(freshTask.getLastRunStartTimestamp())
+ ", freshTask.getLastRunFinishTimestamp()=" + longTimeToString(freshTask.getLastRunFinishTimestamp()));

Expand Down

0 comments on commit 583cb26

Please sign in to comment.