Skip to content

Commit

Permalink
[JENKINS-40909] Ensure serial form compatibility of executions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Jan 10, 2017
1 parent 32c7e74 commit 9ddd3cc
Show file tree
Hide file tree
Showing 26 changed files with 175 additions and 16 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Expand Up @@ -69,7 +69,7 @@ public final class CatchErrorStep extends Step {

}

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

Execution(StepContext context) {
super(context);
Expand All @@ -87,6 +87,8 @@ public static final class Execution extends StepExecution {
// nothing to do
}

@Override public void onResume() {}

private static final class Callback extends BodyExecutionCallback {

@Override public void onSuccess(StepContext context, Object result) {
Expand Down
Expand Up @@ -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;

Expand Down Expand Up @@ -96,6 +96,8 @@ public static final class Execution extends StepExecution {
// should be no need to do anything special (but verify in JENKINS-26148)
}

@Override public void onResume() {}

}

private static final class ExpanderImpl extends EnvironmentExpander {
Expand Down
Expand Up @@ -63,7 +63,7 @@ public List<String> getOverrides() {
return new Execution(overrides, context);
}

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

private static final long serialVersionUID = 1;

Expand All @@ -87,6 +87,8 @@ public static class Execution extends StepExecution {
// should be no need to do anything special (but verify in JENKINS-26148)
}

@Override public void onResume() {}

}

private static final class ExpanderImpl extends EnvironmentExpander {
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -104,6 +104,8 @@ public void stop(Throwable cause) throws Exception {
body.cancel(cause);
}

@Override public void onResume() {}

private static final long serialVersionUID = 1L;

}
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Expand Up @@ -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;

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

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

Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -84,6 +84,7 @@ public void run() {
}
}, delay, TimeUnit.MILLISECONDS);
} else {
listener().getLogger().println("Timeout expired " + Util.getTimeSpanString(- delay) + " ago");
cancel();
}
}
Expand Down
Expand Up @@ -45,7 +45,7 @@ public final class WaitForConditionStep extends Step {
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;
Expand Down Expand Up @@ -80,7 +80,6 @@ public static final class Execution extends StepExecution {
}

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

}

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

private static final long serialVersionUID = 1;

Expand Down Expand Up @@ -100,6 +100,8 @@ public static class Execution extends StepExecution {
getContext().onFailure(cause);
}

@Override public void onResume() {}

}

}
Expand Up @@ -220,6 +220,8 @@ private static class UpcaseFilter extends ConsoleLogFilter implements Serializab
}
}

// 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.
Expand Down
Expand Up @@ -138,4 +138,6 @@ public class EnvStepRunTest {
});
}

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

}
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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));
}
});
}
}
Expand Up @@ -175,4 +175,7 @@ public class WaitForConditionStepTest {
});
}

// 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 @@
2
@@ -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.