Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 5d2b232
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
22 changes: 14 additions & 8 deletions pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand All @@ -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>
Expand Down
Expand Up @@ -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;

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

Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 5d2b232

Please sign in to comment.