Search in sources :

Example 6 with ProcessWrapper

use of com.thoughtworks.go.util.ProcessWrapper in project gocd by gocd.

the class KillAllChildProcessTaskBuilderTest method shouldKillAllChildProcessOnbuild.

//11 minutes
@Test(timeout = 11 * 60 * 1000)
public void shouldKillAllChildProcessOnbuild() throws Exception {
    ProcessWrapper processWrapper = CommandLine.createCommandLine("sleep").withArg(String.valueOf(10 * 60)).execute(ProcessOutputStreamConsumer.inMemoryConsumer(), new EnvironmentVariableContext(), //60 mins
    null);
    assertThat(processWrapper.isRunning(), is(true));
    BuildLogElement log = mock(BuildLogElement.class);
    DefaultGoPublisher publisher = mock(DefaultGoPublisher.class);
    EnvironmentVariableContext environmentVariableContext = mock(EnvironmentVariableContext.class);
    long before = getSystemTime();
    Builder builder = new KillAllChildProcessTaskBuilder().createBuilder(builderFactory, new KillAllChildProcessTask(), null, null);
    builder.build(log, publisher, environmentVariableContext, null);
    assertThat(processWrapper.waitForExit(), is(greaterThan(0)));
    //min = 10; sec = 60*min; mills = 1000*sec; micro = 1000*mills; nano = 1000*micro;
    assertThat(getSystemTime() - before, is(lessThan(10 * 60 * 1000 * 1000 * 1000L)));
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper) BuildLogElement(com.thoughtworks.go.domain.BuildLogElement) DefaultGoPublisher(com.thoughtworks.go.work.DefaultGoPublisher) Builder(com.thoughtworks.go.domain.builder.Builder) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) KillAllChildProcessTask(com.thoughtworks.go.domain.KillAllChildProcessTask) Test(org.junit.Test)

Aggregations

ProcessWrapper (com.thoughtworks.go.util.ProcessWrapper)6 BuildLogElement (com.thoughtworks.go.domain.BuildLogElement)1 KillAllChildProcessTask (com.thoughtworks.go.domain.KillAllChildProcessTask)1 Builder (com.thoughtworks.go.domain.builder.Builder)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)1 IOException (java.io.IOException)1 Test (org.junit.Test)1