Skip to content

Commit

Permalink
don't call watch dog if we didn't even start (fixes #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Sep 6, 2018
1 parent 32e9220 commit 4281c87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/main/java/ch/vorburger/exec/ManagedProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ protected synchronized void startExecute() throws ManagedProcessException {
} catch (IOException e) {
throw new ManagedProcessException("Launch failed: " + commandLine, e);
}
isAlive = watchDog.isWatching(); //check watchdog is watching as DefaultExecutor sets watchDog if process started successfully

// We now must give the system a say 100ms chance to run the background
// thread now, otherwise the resultHandler in checkResult() won't work.
Expand All @@ -216,6 +215,10 @@ protected synchronized void startExecute() throws ManagedProcessException {
throw handleInterruptedException(e);
}
checkResult();

// watchDog.isWatching() blocks if the process never started or already finished,
// so we have to do it only after checkResult() had a chance to throw ManagedProcessException
isAlive = watchDog.isWatching(); // check watchdog is watching as DefaultExecutor sets watchDog if process started successfully
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/ch/vorburger/exec/ManagedProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public void waitForMustFailIfNeverStarted() throws Exception {
p.waitForExit();
}

@Test(expected = ManagedProcessException.class)
public void startForMustFailForWrongExecutable() throws Exception {
ManagedProcess p = new ManagedProcessBuilder("someExec").build();
p.start();
}

@Test
public void testWaitForSeenMessageIfAlreadyTerminated() throws Exception {
SomeSelfTerminatingExec exec = someSelfTerminatingExec();
Expand Down

0 comments on commit 4281c87

Please sign in to comment.