Skip to content

Commit

Permalink
Added test for stop.
Browse files Browse the repository at this point in the history
JENKINS-22641 means that this does not work in 1.554.3, so need to bump up the dependency to 1.565.3.
  • Loading branch information
jglick committed Apr 10, 2015
1 parent 0fe3a2e commit fc48f44
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.554.3</version>
<version>1.565.3</version>
</parent>
<artifactId>durable-task</artifactId>
<version>1.5-SNAPSHOT</version>
Expand Down
@@ -1,7 +1,32 @@
/*
* The MIT License
*
* Copyright 2015 CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jenkinsci.plugins.durabletask;

import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.util.StreamTaskListener;
import org.junit.Assert;
import org.junit.Assume;
Expand All @@ -11,18 +36,18 @@

import java.io.ByteArrayOutputStream;
import java.io.File;
import org.junit.Before;

/**
* @author Kohsuke Kawaguchi
*/
public class BourneShellScriptTest extends Assert {
@Rule
public JenkinsRule j = new JenkinsRule();

@Test
public void smokeTest() throws Exception {
@Before public void unix() {
Assume.assumeTrue("This test is only for Unix", File.pathSeparatorChar==':');
}

@Test
public void smokeTest() throws Exception {
StreamTaskListener l = StreamTaskListener.fromStdout();
FilePath ws = j.jenkins.getRootPath();

Expand All @@ -44,4 +69,27 @@ public void smokeTest() throws Exception {

c.cleanup(ws);
}

@Test public void stop() throws Exception {
StreamTaskListener listener = StreamTaskListener.fromStdout();
FilePath ws = j.jenkins.getRootPath();
Launcher launcher = j.jenkins.createLauncher(listener);
// Have observed both SIGTERM and SIGCHLD, perhaps depending on which process (the written sh, or sleep) gets the signal first.
// TODO without the `trap … EXIT` the other handlers do not seem to get run, and we get exit code 143 (~ uncaught SIGTERM). Why?
Controller c = new BourneShellScript("trap 'echo got SIGCHLD; exit 99' CHLD; trap 'echo got SIGTERM; exit 99' TERM; trap 'echo exiting' EXIT; sleep 999").launch(new EnvVars(), ws, launcher, listener);
Thread.sleep(1000);
c.stop(ws, launcher);
while (c.exitStatus(ws)==null) {
Thread.sleep(100);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
c.writeLog(ws, baos);
String log = baos.toString();
System.out.println(log);
assertEquals(99, c.exitStatus(ws).intValue());
assertTrue(log.contains("sleep 999"));
assertTrue(log.contains("got SIG"));
c.cleanup(ws);
}

}

0 comments on commit fc48f44

Please sign in to comment.