Skip to content

Commit

Permalink
Destroy xUnit runner process if build is aborted. Fixes issue# 14
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett committed Aug 6, 2016
1 parent 623969b commit 1844956
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ public boolean isFinished()
return myFuture.isDone();
}

protected abstract void cancelBuild();

public void interrupt()
{
logger.message("Attempt to interrupt build process");
cancelBuild();
myFuture.cancel(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class XUnitBuildProcess extends FutureBasedBuildProcess {
private final AgentRunningBuild buildingAgent;
private final BuildRunnerContext context;
private Process testRunnerProcess;

public XUnitBuildProcess(@NotNull final BuildRunnerContext context) {
super(context);
Expand All @@ -41,6 +42,13 @@ private List<String> getAssemblies(final String rawAssemblyParameter) {
return assemblies;
}

protected void cancelBuild() {
if (testRunnerProcess == null)
return;

testRunnerProcess.destroy();
}

public BuildFinishedStatus call() throws Exception {
try {
String version = getParameter(StringConstants.ParameterName_XUnitVersion);
Expand Down Expand Up @@ -83,20 +91,20 @@ public BuildFinishedStatus call() throws Exception {
env.put(kvp.getKey(), kvp.getValue());
}

Process process = processBuilder.start();
testRunnerProcess = processBuilder.start();

redirectStreamToLogger(process.getInputStream(), new RedirectionTarget() {
redirectStreamToLogger(testRunnerProcess.getInputStream(), new RedirectionTarget() {
public void redirect(String s) {
logger.message(s);
}
});
redirectStreamToLogger(process.getErrorStream(), new RedirectionTarget() {
redirectStreamToLogger(testRunnerProcess.getErrorStream(), new RedirectionTarget() {
public void redirect(String s) {
logger.warning(s);
}
});

int exitCode = process.waitFor();
int exitCode = testRunnerProcess.waitFor();
if(exitCode != 0) {
logger.warning("Test runner exited with non-zero status!");
status = BuildFinishedStatus.FINISHED_FAILED;
Expand Down

0 comments on commit 1844956

Please sign in to comment.