Skip to content
Permalink
Browse files

[JENKINS-40909] Ensure serial form compatibility of executions.

  • Loading branch information
jglick committed Jan 10, 2017
1 parent 32c7e74 commit 9ddd3cca90bec3f3f08ef8179d1a5e17544cc75a
Showing with 175 additions and 16 deletions.
  1. +3 −3 pom.xml
  2. +3 −1 src/main/java/org/jenkinsci/plugins/workflow/steps/CatchErrorStep.java
  3. +3 −1 src/main/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStep.java
  4. +3 −1 src/main/java/org/jenkinsci/plugins/workflow/steps/EnvStep.java
  5. +3 −1 src/main/java/org/jenkinsci/plugins/workflow/steps/PushdStep.java
  6. +3 −1 src/main/java/org/jenkinsci/plugins/workflow/steps/RetryStepExecution.java
  7. +1 −2 src/main/java/org/jenkinsci/plugins/workflow/steps/SleepStep.java
  8. +4 −3 src/main/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepExecution.java
  9. +1 −2 src/main/java/org/jenkinsci/plugins/workflow/steps/WaitForConditionStep.java
  10. +3 −1 src/main/java/org/jenkinsci/plugins/workflow/steps/WithContextStep.java
  11. +2 −0 src/test/java/org/jenkinsci/plugins/workflow/steps/CoreWrapperStepTest.java
  12. +2 −0 src/test/java/org/jenkinsci/plugins/workflow/steps/EnvStepRunTest.java
  13. +14 −0 src/test/java/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest.java
  14. +3 −0 src/test/java/org/jenkinsci/plugins/workflow/steps/WaitForConditionStepTest.java
  15. +1 −0 ...urces/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/3.log
  16. +1 −0 ...urces/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/5.log
  17. +37 −0 ...s/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/build.xml
  18. +6 −0 ...sources/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/log
  19. BIN ...org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/program.dat
  20. +7 −0 .../jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/workflow/2.xml
  21. +18 −0 .../jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/workflow/3.xml
  22. +16 −0 .../jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/workflow/4.xml
  23. +18 −0 .../jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/builds/1/workflow/5.xml
  24. +15 −0 ...resources/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/config.xml
  25. +1 −0 ...rces/org/jenkinsci/plugins/workflow/steps/TimeoutStepTest/serialForm/jobs/timeout/nextBuildNumber
  26. +7 −0 ...rkflow/steps/TimeoutStepTest/serialForm/org.jenkinsci.plugins.workflow.flow.FlowExecutionList.xml
@@ -28,8 +28,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.17</version>
<relativePath />
<version>2.19</version>
<relativePath/>
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
@@ -68,7 +68,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.6</version>
<version>2.7-20170109.224808-1</version> <!-- TODO https://github.com/jenkinsci/workflow-step-api-plugin/pull/17 -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -69,7 +69,7 @@

}

public static final class Execution extends StepExecution {
public static final class Execution extends AbstractStepExecutionImpl {

Execution(StepContext context) {
super(context);
@@ -87,6 +87,8 @@
// nothing to do
}

@Override public void onResume() {}

private static final class Callback extends BodyExecutionCallback {

@Override public void onSuccess(StepContext context, Object result) {
@@ -63,7 +63,7 @@ public SimpleBuildWrapper getDelegate() {
return new Execution(delegate, context);
}

public static final class Execution extends StepExecution {
public static final class Execution extends AbstractStepExecutionImpl {

private static final long serialVersionUID = 1;

@@ -96,6 +96,8 @@ public SimpleBuildWrapper getDelegate() {
// should be no need to do anything special (but verify in JENKINS-26148)
}

@Override public void onResume() {}

}

private static final class ExpanderImpl extends EnvironmentExpander {
@@ -63,7 +63,7 @@
return new Execution(overrides, context);
}

public static class Execution extends StepExecution {
public static class Execution extends AbstractStepExecutionImpl {

private static final long serialVersionUID = 1;

@@ -87,6 +87,8 @@
// should be no need to do anything special (but verify in JENKINS-26148)
}

@Override public void onResume() {}

}

private static final class ExpanderImpl extends EnvironmentExpander {
@@ -76,7 +76,7 @@ public String getPath() {

}

public static class Execution extends StepExecution {
public static class Execution extends AbstractStepExecutionImpl {

@SuppressFBWarnings(value="SE_TRANSIENT_FIELD_NOT_RESTORED", justification="Only used when starting.")
private transient final String path;
@@ -104,6 +104,8 @@ public void stop(Throwable cause) throws Exception {
body.cancel(cause);
}

@Override public void onResume() {}

private static final long serialVersionUID = 1L;

}
@@ -7,7 +7,7 @@
/**
* @author Kohsuke Kawaguchi
*/
public class RetryStepExecution extends StepExecution {
public class RetryStepExecution extends AbstractStepExecutionImpl {

@SuppressFBWarnings(value="SE_TRANSIENT_FIELD_NOT_RESTORED", justification="Only used when starting.")
private transient final int count;
@@ -33,6 +33,8 @@ public void stop(Throwable cause) throws Exception {
body.cancel(cause);
}

@Override public void onResume() {}

private static class Callback extends BodyExecutionCallback {

private int left;
@@ -66,7 +66,7 @@ public TimeUnit getUnit() {
return new Execution(this, context);
}

public static final class Execution extends StepExecution {
public static final class Execution extends AbstractStepExecutionImpl {

private static final long serialVersionUID = 1L;

@@ -115,7 +115,6 @@ private void setupTimer(long now) {
}

@Override public void onResume() {
super.onResume();
setupTimer(System.currentTimeMillis());
}

@@ -21,7 +21,7 @@
import org.jenkinsci.plugins.workflow.graphanalysis.LinearBlockHoppingScanner;

@SuppressFBWarnings("SE_INNER_CLASS")
public class TimeoutStepExecution extends StepExecution {
public class TimeoutStepExecution extends AbstractStepExecutionImpl {

private static final Logger LOGGER = Logger.getLogger(TimeoutStepExecution.class.getName());
private static final long GRACE_PERIOD = Main.isUnitTest ? /* 5s */5_000 : /* 1m */60_000;
@@ -72,8 +72,8 @@ private TaskListener listener() {
* @param now Current time in milliseconds.
*/
private void setupTimer(final long now) {
if (end > now) {
long delay = end - now;
long delay = end - now;
if (delay > 0) {
if (!forcible) {
listener().getLogger().println("Timeout set to expire in " + Util.getTimeSpanString(delay));
}
@@ -84,6 +84,7 @@ public void run() {
}
}, delay, TimeUnit.MILLISECONDS);
} else {
listener().getLogger().println("Timeout expired " + Util.getTimeSpanString(- delay) + " ago");
cancel();
}
}
@@ -45,7 +45,7 @@
return new Execution(context);
}

public static final class Execution extends StepExecution {
public static final class Execution extends AbstractStepExecutionImpl {

private static final long serialVersionUID = 1;
private volatile BodyExecution body;
@@ -80,7 +80,6 @@
}

@Override public void onResume() {
super.onResume();
recurrencePeriod = MIN_RECURRENCE_PERIOD;
if (body == null) {
// Restarted while waiting for the timer to go off. Rerun now.
@@ -71,7 +71,7 @@

}

public static class Execution extends StepExecution {
public static class Execution extends AbstractStepExecutionImpl {

private static final long serialVersionUID = 1;

@@ -100,6 +100,8 @@
getContext().onFailure(cause);
}

@Override public void onResume() {}

}

}
@@ -220,6 +220,8 @@
}
}

// TODO add @LocalData serialForm test proving compatibility with executions dating back to workflow 1.4.3 on 1.580.1

// TODO add to jenkins-test-harness
/**
* Akin to {@link JenkinsRule#createSlave(String, String, EnvVars)} but allows {@link Computer#getEnvironment} to be controlled rather than directly modifying launchers.
@@ -138,4 +138,6 @@
});
}

// TODO add @LocalData serialForm test proving compatibility with executions dating back to workflow 1.4.3 on 1.580.1

}
@@ -26,6 +26,7 @@

import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.model.listeners.RunListener;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -47,6 +48,7 @@
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.RestartableJenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import org.jvnet.hudson.test.recipes.LocalData;
import org.kohsuke.stapler.DataBoundConstructor;

public class TimeoutStepTest extends Assert {
@@ -252,4 +254,16 @@ private Execution(StepContext context) {

// TODO: timeout inside parallel

@Issue("JENKINS-39134")
@LocalData
@Test public void serialForm() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.getItemByFullName("timeout", WorkflowJob.class);
WorkflowRun b = p.getBuildByNumber(1);
RunListener.fireStarted(b, TaskListener.NULL);
story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
}
});
}
}
@@ -175,4 +175,7 @@
});
}

// TODO add @LocalData serialForm test proving compatibility with executions dating back to workflow 1.4.3 on 1.580.1
// (same for RetryStep, though where is its test?)

}
@@ -0,0 +1 @@
Timeout set to expire in 27,397 yr
@@ -0,0 +1 @@
Sleeping for 2 min 0 sec
@@ -0,0 +1,37 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-build plugin="workflow-job@1.4.3">
<actions>
<hudson.model.CauseAction>
<causes>
<hudson.model.Cause_-UserIdCause/>
</causes>
</hudson.model.CauseAction>
</actions>
<queueId>1</queueId>
<timestamp>1484006053835</timestamp>
<startTime>1484006053839</startTime>
<duration>0</duration>
<keepLog>false</keepLog>
<execution class="org.jenkinsci.plugins.workflow.cps.CpsFlowExecution">
<result>SUCCESS</result>
<script>timeout(time: 9999999, unit: &apos;DAYS&apos;) {
sleep time: 2, unit: &apos;MINUTES&apos;
}
</script>
<loadedScripts class="map"/>
<owner class="flow-owner">
<job>timeout</job>
<id>1</id>
</owner>
<iota>5</iota>
<head>1:5</head>
<start>2</start>
</execution>
<logsToCopy class="linked-hash-map">
<entry>
<string>5</string>
<long>25</long>
</entry>
</logsToCopy>
<checkouts class="hudson.util.PersistedList"/>
</flow-build>
@@ -0,0 +1,6 @@
Started by user ha:AAAAlh+LCAAAAAAAAP9b85aBtbiIQTGjNKU4P08vOT+vOD8nVc83PyU1x6OyILUoJzMv2y+/JJUBAhiZGBgqihhk0NSjKDWzXb3RdlLBUSYGJk8GtpzUvPSSDB8G5tKinBIGIZ+sxLJE/ZzEvHT94JKizLx0a6BxUmjGOUNodHsLgAzOEgYu/dLi1CL9vNKcHACFIKlWvwAAAA==anonymous
Running: Enforce time limit : Start
Timeout set to expire in 27,397 yr
Running: Enforce time limit : Body : Start
Running: Sleep
Sleeping for 2 min 0 sec
Binary file not shown.
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag plugin="workflow-support@1.4.3">
<node class="org.jenkinsci.plugins.workflow.graph.FlowStartNode" plugin="workflow-api@2.8">
<parentIds/>
<id>2</id>
</node>
</org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag>
@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='UTF-8'?>
<org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag plugin="workflow-support@1.4.3">
<node class="org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode" plugin="workflow-cps@1.4.3">
<parentIds>
<string>2</string>
</parentIds>
<id>3</id>
<descriptorId>org.jenkinsci.plugins.workflow.steps.TimeoutStep</descriptorId>
</node>
<actions>
<org.jenkinsci.plugins.workflow.support.actions.LogActionImpl>
<charset>UTF-8</charset>
</org.jenkinsci.plugins.workflow.support.actions.LogActionImpl>
<org.jenkinsci.plugins.workflow.actions.TimingAction plugin="workflow-api@2.8">
<startTime>1484006054796</startTime>
</org.jenkinsci.plugins.workflow.actions.TimingAction>
</actions>
</org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag>
@@ -0,0 +1,16 @@
<?xml version='1.0' encoding='UTF-8'?>
<org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag plugin="workflow-support@1.4.3">
<node class="org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode" plugin="workflow-cps@1.4.3">
<parentIds>
<string>3</string>
</parentIds>
<id>4</id>
<descriptorId>org.jenkinsci.plugins.workflow.steps.TimeoutStep</descriptorId>
</node>
<actions>
<org.jenkinsci.plugins.workflow.actions.BodyInvocationAction plugin="workflow-api@2.8"/>
<org.jenkinsci.plugins.workflow.actions.TimingAction plugin="workflow-api@2.8">
<startTime>1484006054823</startTime>
</org.jenkinsci.plugins.workflow.actions.TimingAction>
</actions>
</org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag>
@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='UTF-8'?>
<org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag plugin="workflow-support@1.4.3">
<node class="org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode" plugin="workflow-cps@1.4.3">
<parentIds>
<string>4</string>
</parentIds>
<id>5</id>
<descriptorId>org.jenkinsci.plugins.workflow.steps.SleepStep</descriptorId>
</node>
<actions>
<org.jenkinsci.plugins.workflow.support.actions.LogActionImpl>
<charset>UTF-8</charset>
</org.jenkinsci.plugins.workflow.support.actions.LogActionImpl>
<org.jenkinsci.plugins.workflow.actions.TimingAction plugin="workflow-api@2.8">
<startTime>1484006054830</startTime>
</org.jenkinsci.plugins.workflow.actions.TimingAction>
</actions>
</org.jenkinsci.plugins.workflow.support.storage.SimpleXStreamFlowNodeStorage_-Tag>
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@1.4.3">
<actions/>
<description></description>
<keepDependencies>false</keepDependencies>
<properties/>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@1.4.3">
<script>timeout(time: 9999999, unit: &apos;DAYS&apos;) {
sleep time: 2, unit: &apos;MINUTES&apos;
}
</script>
<sandbox>true</sandbox>
</definition>
<triggers/>
</flow-definition>
@@ -0,0 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<list>
<flow-owner plugin="workflow-job@1.4.3">
<job>timeout</job>
<id>1</id>
</flow-owner>
</list>

0 comments on commit 9ddd3cc

Please sign in to comment.
You can’t perform that action at this time.