Skip to content
Permalink
Browse files
Merge branch 'JENKINS-22641' of github.com:christ66/jenkins
  • Loading branch information
jglick committed Jul 21, 2014
2 parents f43a450 + 9ac68b9 commit f03e67a49bf01343635c60e894b9617483a03011
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
@@ -37,19 +37,10 @@
import hudson.util.ProcessTree.OSProcess;
import hudson.util.ProcessTreeRemoting.IOSProcess;
import hudson.util.ProcessTreeRemoting.IProcessTree;
import org.apache.commons.io.FileUtils;
import org.jvnet.winp.WinProcess;
import org.jvnet.winp.WinpException;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.Serializable;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -680,7 +671,7 @@ public synchronized List<String> getArguments() {
return arguments;
arguments = new ArrayList<String>();
try {
byte[] cmdline = FileUtils.readFileToByteArray(getFile("cmdline"));
byte[] cmdline = readFileToByteArray(getFile("cmdline"));
int pos=0;
for (int i = 0; i < cmdline.length; i++) {
byte b = cmdline[i];
@@ -702,7 +693,7 @@ public synchronized EnvVars getEnvironmentVariables() {
return envVars;
envVars = new EnvVars();
try {
byte[] environ = FileUtils.readFileToByteArray(getFile("environ"));
byte[] environ = readFileToByteArray(getFile("environ"));
int pos=0;
for (int i = 0; i < environ.length; i++) {
byte b = environ[i];
@@ -718,6 +709,15 @@ public synchronized EnvVars getEnvironmentVariables() {
return envVars;
}
}

public byte[] readFileToByteArray(File file) throws IOException {
InputStream in = org.apache.commons.io.FileUtils.openInputStream(file);
try {
return org.apache.commons.io.IOUtils.toByteArray(in);
} finally {
in.close();
}
}
}

/**
@@ -1,14 +1,13 @@
package hudson.util;

import hudson.model.FreeStyleProject;
import hudson.Functions;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.tasks.Maven;

import org.easymock.EasyMock;
import hudson.tasks.Shell;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.ExtractResourceSCM;
import org.jvnet.hudson.test.HudsonTestCase;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;

public class ProcessTreeKillerTest extends HudsonTestCase {

@@ -34,4 +33,25 @@ public void testManualAbortProcess() throws Exception {

}

@Bug(22641)
public void testProcessProperlyKilledUnix() throws Exception {
ProcessTree.enabled = true;
if (Functions.isWindows()) return; // This test does not involve windows.

FreeStyleProject sleepProject = createFreeStyleProject();
FreeStyleProject processJob = createFreeStyleProject();

sleepProject.getBuildersList().add(new Shell("nohup sleep 100000 &"));

assertBuildStatusSuccess(sleepProject.scheduleBuild2(0).get());

processJob.getBuildersList().add(new Shell("ps -ef | grep sleep"));

String log = processJob.scheduleBuild2(0).get().getLog();

System.err.println("LOGS: " + log);

assertFalse("Did not properly kill task", log.contains("sleep 100000"));
}

}

0 comments on commit f03e67a

Please sign in to comment.