Skip to content

Commit

Permalink
Merge pull request #77 from dwnusbaum/JENKINS-54607-upmerge
Browse files Browse the repository at this point in the history
[JENKINS-54607] Merge #76 from stable into master
  • Loading branch information
dwnusbaum committed Nov 30, 2018
2 parents f6372e4 + 74a5bbe commit 7580c53
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TimeoutStepExecution extends AbstractStepExecutionImpl {
private BodyExecution body;
private transient ScheduledFuture<?> killer;

private final long timeout;
private long timeout;
private long end = 0;

/** Used to track whether this is timing out on inactivity without needing to reference {@link #step}. */
Expand Down Expand Up @@ -189,8 +189,7 @@ private void cancel() {
listener().getLogger().println("Cancelling nested steps due to timeout");
body.cancel(new ExceededTimeout());
forcible = true;
long now = System.currentTimeMillis();
end = now + GRACE_PERIOD;
timeout = GRACE_PERIOD;
resetTimer();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import org.jenkinsci.plugins.workflow.support.visualization.table.FlowGraphTable.Row;
import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep;
import org.junit.*;

import static org.hamcrest.Matchers.lessThan;
import static org.junit.Assert.assertEquals;
import static org.junit.Assume.*;
import org.junit.runners.model.Statement;
Expand Down Expand Up @@ -371,7 +373,7 @@ private Execution(StepContext context) {
getContext().get(TaskListener.class).getLogger().println("ignoring " + cause);
}
}
@TestExtension("unresponsiveBody") public static class DescriptorImpl extends StepDescriptor {
@TestExtension({"unresponsiveBody", "gracePeriod"}) public static class DescriptorImpl extends StepDescriptor {
@Override public String getFunctionName() {
return "unkillable";
}
Expand Down Expand Up @@ -407,4 +409,16 @@ private Execution(StepContext context) {
}
});
}

@Issue("JENKINS-54607")
@Test public void gracePeriod() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("timeout(time: 15, unit: 'SECONDS') {unkillable()}", true));
story.j.assertBuildStatus(Result.ABORTED, p.scheduleBuild2(0).get());
assertThat(p.getLastBuild().getDuration(), lessThan(29_000L)); // 29 seconds
}
});
}
}

0 comments on commit 7580c53

Please sign in to comment.