Skip to content
Permalink
Browse files
[JENKINS-40368] Test that reproduces the hard kill bug.
  • Loading branch information
abayer committed Feb 21, 2017
1 parent 3a8fb0e commit 4d396d8acb03788f5424d93c9e214ef86c8c074c
Showing with 45 additions and 0 deletions.
  1. +45 −0 src/test/java/org/jenkins/plugins/lockableresources/LockStepTest.java
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.concurrent.Semaphore;

import hudson.model.Executor;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
@@ -25,6 +26,8 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;

import static org.junit.Assert.assertNotNull;

public class LockStepTest {

@Rule
@@ -516,6 +519,48 @@ public void evaluate() throws Throwable {
});
}

@Issue("JENKINS-40368")
@Test
public void hardKillWithWaitingRuns() throws Exception {
story.addStep(new Statement() {
@Override
public void evaluate() throws Throwable {
LockableResourcesManager.get().createResource("resource1");
WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("retry(99) {\n" +
" lock('resource1') {\n" +
" semaphore('wait-inside')\n" +
" }\n" +
"}", true));

WorkflowRun prevBuild = null;
for (int i = 0; i < 3; i++) {
WorkflowRun rNext = p.scheduleBuild2(0).waitForStart();
if (prevBuild != null) {
story.j.waitForMessage("[resource1] is locked, waiting...", rNext);
Executor ex = prevBuild.getExecutor();
assertNotNull(ex);
ex.interrupt();
story.j.waitForMessage("Click here to forcibly terminate running steps", prevBuild);
prevBuild.doTerm();
story.j.waitForMessage("Click here to forcibly kill entire build", prevBuild);
prevBuild.doKill();
story.j.waitForMessage("Hard kill!", prevBuild);
story.j.waitForCompletion(prevBuild);
story.j.assertBuildStatus(Result.ABORTED, prevBuild);
}

story.j.waitForMessage("Lock acquired on [resource1]", rNext);

SemaphoreStep.waitForStart("wait-inside/" + (i + 1), rNext);
prevBuild = rNext;
}
SemaphoreStep.success("wait-inside/3", prevBuild);
story.j.assertBuildStatus(Result.SUCCESS, story.j.waitForCompletion(prevBuild));
}
});
}

@Issue("JENKINS-40879")
@Test
public void parallelLockRelease() throws Exception {

0 comments on commit 4d396d8

Please sign in to comment.