Skip to content
Permalink
Browse files

Merge pull request #24 from jglick/timeout-block-JENKINS-34637

[JENKINS-34637] Test for timeout bug
  • Loading branch information...
jglick committed Oct 24, 2016
2 parents f541cd2 + 9b369e6 commit 5d2b2327b7ae5daec98bf747520c2960c8685f0c
22 pom.xml
@@ -28,8 +28,8 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>2.14</version>
<relativePath />
<version>2.17</version>
<relativePath/>
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
@@ -66,7 +66,7 @@
</properties>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.3</version>
</dependency>
@@ -76,7 +76,7 @@
<version>1.13</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-step-api</artifactId>
<version>2.3</version>
<classifier>tests</classifier>
@@ -85,7 +85,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-api</artifactId>
<version>2.1</version>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -95,13 +95,13 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.10</version>
<version>2.20</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.10</version>
<version>2.20</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
@@ -120,7 +120,13 @@
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.1</version>
<version>2.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-support</artifactId>
<version>2.10</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
@@ -2,6 +2,8 @@

import com.google.inject.Inject;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.Util;
import hudson.model.TaskListener;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

@@ -15,6 +17,7 @@
public class TimeoutStepExecution extends AbstractStepExecutionImpl {
@Inject(optional=true)
private transient TimeoutStep step;
@StepContextParameter private transient TaskListener listener;
private BodyExecution body;
private transient ScheduledFuture<?> killer;

@@ -45,17 +48,24 @@ public void onResume() {
*/
private void setupTimer(final long now) {
if (end > now) {
long delay = end - now;
listener.getLogger().println("Timeout set to expire in " + Util.getTimeSpanString(delay));
killer = Timer.get().schedule(new Runnable() {
@Override
public void run() {
body.cancel(new ExceededTimeout());
cancel();
}
}, end - now, TimeUnit.MILLISECONDS);
}, delay, TimeUnit.MILLISECONDS);
} else {
body.cancel(new ExceededTimeout());
cancel();
}
}

private void cancel() {
listener.getLogger().println("Cancelling nested steps due to timeout");
body.cancel(new ExceededTimeout());
}

@Override
public void stop(Throwable cause) throws Exception {
if (body!=null)
@@ -18,8 +18,6 @@
import org.jvnet.hudson.test.RestartableJenkinsRule;

import java.util.List;
import org.jenkinsci.plugins.workflow.steps.SleepStep;
import org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution;

/**
* @author Kohsuke Kawaguchi
@@ -47,6 +45,21 @@ public void evaluate() throws Throwable {
});
}

@Issue("JENKINS-34637")
@Test
public void basicWithBlock() {
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
"node { timeout(time:5, unit:'SECONDS') { withEnv([]) { sleep 7; echo 'NotHere' } } }"));
WorkflowRun b = story.j.assertBuildStatus(Result.ABORTED, p.scheduleBuild2(0).get());
story.j.assertLogNotContains("NotHere", b);
}
});
}

@Test
public void killingParallel() throws Exception {
story.addStep(new Statement() {

0 comments on commit 5d2b232

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