Search in sources :

Example 1 with CommandTimeoutException

use of com.google.copybara.util.CommandTimeoutException in project copybara by google.

the class CommandRunnerTest method testTimeoutCustomExitCode.

@Test
public void testTimeoutCustomExitCode() throws Exception {
    Command command = bashCommand("" + "trap 'exit 42' SIGTERM SIGINT\n" + "echo stdout msg\n" + ">&2 echo stderr msg\n" + "sleep 10\n");
    CommandTimeoutException e = assertThrows(CommandTimeoutException.class, () -> runCommand(new CommandRunner(command, Duration.ofSeconds(1))));
    assertThat(e.getTimeout()).isEquivalentAccordingToCompareTo(Duration.ofSeconds(1));
    assertThat(e.getOutput().getStderr()).contains("stderr msg");
    assertThat(e.getMessage()).containsMatch("Command '.*' killed by Copybara after timeout \\(1s\\)");
    assertThat(e.getOutput().getStdout()).contains("stdout msg");
}
Also used : CommandTimeoutException(com.google.copybara.util.CommandTimeoutException) Command(com.google.copybara.shell.Command) CommandRunner(com.google.copybara.util.CommandRunner) Test(org.junit.Test)

Example 2 with CommandTimeoutException

use of com.google.copybara.util.CommandTimeoutException in project copybara by google.

the class CommandRunnerTest method testTimeout.

@Test
public void testTimeout() throws Exception {
    Command command = bashCommand("" + "echo stdout msg\n" + ">&2 echo stderr msg\n" + "sleep 10\n");
    CommandTimeoutException e = assertThrows(CommandTimeoutException.class, () -> runCommand(new CommandRunner(command, Duration.ofSeconds(1))));
    assertThat(e.getOutput().getStdout()).contains("stdout msg");
    assertThat(e.getOutput().getStderr()).contains("stderr msg");
    assertThat(e.getMessage()).containsMatch("Command '.*' killed by Copybara after timeout \\(1s\\)");
    assertThat(e.getTimeout()).isEquivalentAccordingToCompareTo(Duration.ofSeconds(1));
}
Also used : CommandTimeoutException(com.google.copybara.util.CommandTimeoutException) Command(com.google.copybara.shell.Command) CommandRunner(com.google.copybara.util.CommandRunner) Test(org.junit.Test)

Aggregations

Command (com.google.copybara.shell.Command)2 CommandRunner (com.google.copybara.util.CommandRunner)2 CommandTimeoutException (com.google.copybara.util.CommandTimeoutException)2 Test (org.junit.Test)2