diff --git a/test/src/test/java/hudson/util/ProcessTreeKillerTest.java b/test/src/test/java/hudson/util/ProcessTreeKillerTest.java index 85ae3eb8565debcb580ec97480f90706d26c53e4..4c79b2f17aba640ee6539468420679b93854a869 100644 --- a/test/src/test/java/hudson/util/ProcessTreeKillerTest.java +++ b/test/src/test/java/hudson/util/ProcessTreeKillerTest.java @@ -35,35 +35,35 @@ public class ProcessTreeKillerTest { @Rule public JenkinsRule j = new JenkinsRule(); private Process process; - + @After public void tearDown() throws Exception { ProcessTree.vetoersExist = null; if (null != process) process.destroy(); - } - + } + @Test - public void manualAbortProcess() throws Exception { - ProcessTree.enabled = true; - FreeStyleProject project = j.createFreeStyleProject(); + public void manualAbortProcess() throws Exception { + ProcessTree.enabled = true; + FreeStyleProject project = j.createFreeStyleProject(); - // this contains a maven project with a single test that sleeps 5s. - project.setScm(new ExtractResourceSCM(getClass().getResource( - "ProcessTreeKiller-test-project.jar"))); - project.getBuildersList().add(new Maven("install", "maven")); + // this contains a maven project with a single test that sleeps 5s. + project.setScm(new ExtractResourceSCM(getClass().getResource( + "ProcessTreeKiller-test-project.jar"))); + project.getBuildersList().add(new Maven("install", "maven")); - // build the project, wait until tests are running, then cancel. - project.scheduleBuild2(0).waitForStart(); + // build the project, wait until tests are running, then cancel. + project.scheduleBuild2(0).waitForStart(); FreeStyleBuild b = project.getLastBuild(); b.doStop(); - Thread.sleep(1000); + Thread.sleep(1000); - // will fail (at least on windows) if test process is still running - b.getWorkspace().deleteRecursive(); - } + // will fail (at least on windows) if test process is still running + b.getWorkspace().deleteRecursive(); + } @Test public void killNullProcess() throws Exception { @@ -106,6 +106,7 @@ public class ProcessTreeKillerTest { assertTrue("Process should be dead", !spawner.proc.isAlive()); } } + public static final class SpawnBuilder extends TestBuilder { private Proc proc; @@ -117,7 +118,7 @@ public class ProcessTreeKillerTest { return true; } } - + @Test @Issue("JENKINS-9104") public void considersKillingVetos() throws Exception { @@ -146,35 +147,35 @@ public class ProcessTreeKillerTest { // Means the process is still running } } - + @Test @Issue("JENKINS-9104") public void considersKillingVetosOnSlave() throws Exception { // on some platforms where we fail to list any processes, this test will // just not work assumeTrue(ProcessTree.get() != ProcessTree.DEFAULT); - + // Define a process we (shouldn't) kill ProcessBuilder pb = new ProcessBuilder(); pb.environment().put("cookie", "testKeepDaemonsAlive"); - + if (File.pathSeparatorChar == ';') { pb.command("cmd"); } else { pb.command("sleep", "5m"); } - + // Create an agent so we can tell it to kill the process Slave s = j.createSlave(); s.toComputer().connect(false).get(); - + // Start the process process = pb.start(); - + // Call killall (somewhat roundabout though) to (not) kill it StringWriter out = new StringWriter(); s.createLauncher(new StreamTaskListener(out)).kill(ImmutableMap.of("cookie", "testKeepDaemonsAlive")); - + try { process.exitValue(); fail("Process should have been excluded from the killing");