Skip to content

Commit 9101f1b

Browse files
authored
Merge pull request #568 from Riliane/flowdurabilitytest-flake
Resolve a race condition in FlowDurabilityTest causing test flakes
2 parents 4e90600 + 37b9011 commit 9101f1b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/test/java/org/jenkinsci/plugins/workflow/cps/FlowDurabilityTest.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,22 @@ static void verifySucceededCleanly(Jenkins j, WorkflowRun run) throws Exception
251251
assertHasTimingAction(run.getExecution());
252252
}
253253

254+
/** A minimal check of resuming the job with no node checks, in case of a dirty shutdown.
255+
* Currently dirty shutdowns have the potential to lose the head node ID if they happen at the moment of writing
256+
* it to build.xml
257+
*/
258+
private static void verifyDirtyResumed(JenkinsRule rule, WorkflowRun run, String logStart) throws Exception {
259+
assertHasTimingAction(run.getExecution());
260+
rule.waitForCompletion(run);
261+
Assert.assertEquals(Result.SUCCESS, run.getResult());
262+
verifyCompletedCleanly(rule.jenkins, run);
263+
//no checking nodes
264+
rule.assertLogContains(logStart, run);
265+
}
266+
254267
/** If it's a {@link SemaphoreStep} we test less rigorously because that blocks async GraphListeners. */
255-
static void verifySafelyResumed(JenkinsRule rule, WorkflowRun run, boolean isSemaphore, String logStart) throws Exception {
256-
assert run.isBuilding();
268+
private static void verifySafelyResumed(JenkinsRule rule, WorkflowRun run, boolean isSemaphore, String logStart) throws Exception {
269+
Assert.assertTrue(run.isBuilding());
257270
FlowExecution exec = run.getExecution();
258271

259272
// Assert that we have the appropriate flow graph entries
@@ -728,7 +741,7 @@ public void evaluate() throws Throwable {
728741
@Override
729742
public void evaluate() throws Throwable {
730743
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
731-
verifySafelyResumed(story.j, run, false, logStart[0]);
744+
verifyDirtyResumed(story.j, run, logStart[0]);
732745
}
733746
});
734747
}
@@ -761,7 +774,6 @@ public void evaluate() throws Throwable {
761774
public void evaluate() throws Throwable {
762775
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
763776
verifyFailedCleanly(story.j.jenkins, run);
764-
assertIncludesNodes(nodesOut, run);
765777
}
766778
});
767779
}
@@ -779,7 +791,7 @@ public void evaluate() throws Throwable {
779791
WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY, false);
780792
FlowExecution exec = run.getExecution();
781793
if (exec instanceof CpsFlowExecution) {
782-
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
794+
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully(); // single node xmls written
783795
}
784796
nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution()));
785797
nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR);
@@ -792,7 +804,6 @@ public void evaluate() throws Throwable {
792804
public void evaluate() throws Throwable {
793805
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
794806
verifyFailedCleanly(story.j.jenkins, run);
795-
assertIncludesNodes(nodesOut, run);
796807
}
797808
});
798809
}

0 commit comments

Comments
 (0)