use of com.google.copybara.shell.Killable in project copybara by google.
the class CommandRunnerTest method testObserverCanTerminate.
@Test
public void testObserverCanTerminate() throws Exception {
KillableObserver tester = new KillableObserver() {
@Override
public void startObserving(Killable killable) {
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
// ignored
}
killable.kill();
}
@Override
public void stopObserving(Killable killable) {
}
};
Command command = bashCommand("" + "echo stdout msg\n" + ">&2 echo stderr msg\n" + "sleep 10\n");
AbnormalTerminationException e = assertThrows(AbnormalTerminationException.class, () -> runCommand(new CommandRunner(command, Duration.ofSeconds(90)).withObserver(tester)));
assertThat(e).hasMessageThat().containsMatch("Process terminated by signal 15");
assertThat(e).hasMessageThat().doesNotContainMatch("Command '.*' killed by Copybara after timeout \\(1s\\)");
}
Aggregations