Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #210 from svanoort/fix-JENKINS-49961
Fix [JENKINS-49961] by avoiding an unsafe save operation when toggling ResumeEnabled if the FlowExecutionOwner is not yet set
  • Loading branch information
abayer committed Mar 12, 2018
2 parents 78b137d + f56c8e5 commit a63e684
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -62,7 +62,7 @@
</pluginRepository>
</pluginRepositories>
<properties>
<jenkins.version>2.60.3</jenkins.version>
<jenkins.version>2.62</jenkins.version>
<java.level>8</java.level>
<no-test-jar>false</no-test-jar>
<git-plugin.version>3.1.0</git-plugin.version>
Expand Down Expand Up @@ -141,7 +141,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.11.2</version>
<version>2.17</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Expand Up @@ -345,7 +345,6 @@ public boolean isResumeBlocked() {
public void setResumeBlocked(boolean resumeBlocked) {
if (this.resumeBlocked != resumeBlocked) {
this.resumeBlocked = resumeBlocked;
saveOwner();
}
}

Expand Down
Expand Up @@ -723,10 +723,10 @@ public void testResumeBlocked() throws Exception {
public void evaluate() throws Throwable {
Jenkins jenkins = story.j.jenkins;
WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY);
run.getParent().setResumeBlocked(true);
FlowExecution exec = run.getExecution();
if (exec instanceof CpsFlowExecution) {
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
((CpsFlowExecution)exec).setResumeBlocked(true);
}
logStart[0] = JenkinsRule.getLog(run);
nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution()));
Expand All @@ -744,6 +744,40 @@ public void evaluate() throws Throwable {
});
}

@Test
@Issue("JENKINS-49961")
public void testResumeBlockedAddedAfterRunStart() throws Exception {
final String jobName = "survivesEverything";
final String[] logStart = new String[1];
final List<FlowNode> nodesOut = new ArrayList<FlowNode>();

story.addStepWithDirtyShutdown(new Statement() {
@Override
public void evaluate() throws Throwable {
Jenkins jenkins = story.j.jenkins;
WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY);
run.getParent().setResumeBlocked(false);
FlowExecution exec = run.getExecution();
if (exec instanceof CpsFlowExecution) {
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
}
logStart[0] = JenkinsRule.getLog(run);
nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution()));
nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR);
run.getParent().setResumeBlocked(true);
}
});

story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
verifyFailedCleanly(story.j.jenkins, run);
assertIncludesNodes(nodesOut, run);
}
});
}

/** Test interrupting build by randomly dying at unpredictable times. */
@Test
@Ignore //Too long to run as part of main suite
Expand Down

0 comments on commit a63e684

Please sign in to comment.