Skip to content

Commit a63e684

Browse files
authored
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
2 parents 78b137d + f56c8e5 commit a63e684

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
</pluginRepository>
6363
</pluginRepositories>
6464
<properties>
65-
<jenkins.version>2.60.3</jenkins.version>
65+
<jenkins.version>2.62</jenkins.version>
6666
<java.level>8</java.level>
6767
<no-test-jar>false</no-test-jar>
6868
<git-plugin.version>3.1.0</git-plugin.version>
@@ -141,7 +141,7 @@
141141
<dependency>
142142
<groupId>org.jenkins-ci.plugins.workflow</groupId>
143143
<artifactId>workflow-job</artifactId>
144-
<version>2.11.2</version>
144+
<version>2.17</version>
145145
<scope>test</scope>
146146
</dependency>
147147
<dependency>

src/main/java/org/jenkinsci/plugins/workflow/cps/CpsFlowExecution.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ public boolean isResumeBlocked() {
345345
public void setResumeBlocked(boolean resumeBlocked) {
346346
if (this.resumeBlocked != resumeBlocked) {
347347
this.resumeBlocked = resumeBlocked;
348-
saveOwner();
349348
}
350349
}
351350

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,10 @@ public void testResumeBlocked() throws Exception {
723723
public void evaluate() throws Throwable {
724724
Jenkins jenkins = story.j.jenkins;
725725
WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY);
726+
run.getParent().setResumeBlocked(true);
726727
FlowExecution exec = run.getExecution();
727728
if (exec instanceof CpsFlowExecution) {
728729
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
729-
((CpsFlowExecution)exec).setResumeBlocked(true);
730730
}
731731
logStart[0] = JenkinsRule.getLog(run);
732732
nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution()));
@@ -744,6 +744,40 @@ public void evaluate() throws Throwable {
744744
});
745745
}
746746

747+
@Test
748+
@Issue("JENKINS-49961")
749+
public void testResumeBlockedAddedAfterRunStart() throws Exception {
750+
final String jobName = "survivesEverything";
751+
final String[] logStart = new String[1];
752+
final List<FlowNode> nodesOut = new ArrayList<FlowNode>();
753+
754+
story.addStepWithDirtyShutdown(new Statement() {
755+
@Override
756+
public void evaluate() throws Throwable {
757+
Jenkins jenkins = story.j.jenkins;
758+
WorkflowRun run = createAndRunSleeperJob(story.j.jenkins, jobName, FlowDurabilityHint.MAX_SURVIVABILITY);
759+
run.getParent().setResumeBlocked(false);
760+
FlowExecution exec = run.getExecution();
761+
if (exec instanceof CpsFlowExecution) {
762+
assert ((CpsFlowExecution) exec).getStorage().isPersistedFully();
763+
}
764+
logStart[0] = JenkinsRule.getLog(run);
765+
nodesOut.addAll(new DepthFirstScanner().allNodes(run.getExecution()));
766+
nodesOut.sort(FlowScanningUtils.ID_ORDER_COMPARATOR);
767+
run.getParent().setResumeBlocked(true);
768+
}
769+
});
770+
771+
story.addStep(new Statement() {
772+
@Override
773+
public void evaluate() throws Throwable {
774+
WorkflowRun run = story.j.jenkins.getItemByFullName(jobName, WorkflowJob.class).getLastBuild();
775+
verifyFailedCleanly(story.j.jenkins, run);
776+
assertIncludesNodes(nodesOut, run);
777+
}
778+
});
779+
}
780+
747781
/** Test interrupting build by randomly dying at unpredictable times. */
748782
@Test
749783
@Ignore //Too long to run as part of main suite

0 commit comments

Comments
 (0)