Search in sources :

Example 11 with ProcessWrapper

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

the class KillAllChildProcessTaskBuilderTest method shouldKillAllChildProcessOnBuild.

@Test
@Timeout(value = 11, unit = MINUTES)
public void shouldKillAllChildProcessOnBuild() throws Exception {
    ProcessWrapper processWrapper = platformSpecificSleepCommand().withArg(String.valueOf(10 * 60)).withEncoding("utf-8").execute(ProcessOutputStreamConsumer.inMemoryConsumer(), new EnvironmentVariableContext(), // 10 mins
    null);
    assertThat(processWrapper.isRunning(), is(true));
    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(publisher, environmentVariableContext, null, null, null, "utf-8");
    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) 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.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 12 with ProcessWrapper

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

the class CommandLine method execute.

/**
 * @deprecated this should not be used outside of this CommandLine(in production code), as using it directly can bypass smudging of sensitive data
 * this is used only in tests
 */
public ProcessWrapper execute(ConsoleOutputStreamConsumer outputStreamConsumer, EnvironmentVariableContext environmentVariableContext, String processTag) {
    ProcessWrapper process = createProcess(environmentVariableContext, outputStreamConsumer, processTag, ERROR_STREAM_PREFIX_FOR_CMDS);
    process.typeInputToConsole(inputs);
    return process;
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper)

Example 13 with ProcessWrapper

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

the class CommandLine method startProcess.

private ProcessWrapper startProcess(EnvironmentVariableContext environmentVariableContext, ConsoleOutputStreamConsumer consumer, String processTag) throws IOException {
    ProcessWrapper process = createProcess(environmentVariableContext, consumer, processTag, ERROR_STREAM_PREFIX_FOR_SCRIPTS);
    process.closeOutputStream();
    return process;
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper)

Example 14 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)).withEncoding("utf-8").execute(ProcessOutputStreamConsumer.inMemoryConsumer(), new EnvironmentVariableContext(), // 60 mins
    null);
    assertThat(processWrapper.isRunning(), is(true));
    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(publisher, environmentVariableContext, null, null, null, "utf-8");
    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) 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)

Example 15 with ProcessWrapper

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

the class CommandLine method execute.

/**
 * This should not be used outside of this CommandLine(in production code), as using it directly can bypass smudging of sensitive data
 */
@TestOnly
public ProcessWrapper execute(ConsoleOutputStreamConsumer outputStreamConsumer, EnvironmentVariableContext environmentVariableContext, ProcessTag processTag) {
    ProcessWrapper process = createProcess(environmentVariableContext, outputStreamConsumer, processTag, ERROR_STREAM_PREFIX_FOR_CMDS);
    process.typeInputToConsole(inputs);
    return process;
}
Also used : ProcessWrapper(com.thoughtworks.go.util.ProcessWrapper) TestOnly(org.jetbrains.annotations.TestOnly)

Aggregations

ProcessWrapper (com.thoughtworks.go.util.ProcessWrapper)18 Test (org.junit.jupiter.api.Test)6 DisabledOnOs (org.junit.jupiter.api.condition.DisabledOnOs)3 KillAllChildProcessTask (com.thoughtworks.go.domain.KillAllChildProcessTask)2 Builder (com.thoughtworks.go.domain.builder.Builder)2 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)2 DefaultGoPublisher (com.thoughtworks.go.work.DefaultGoPublisher)2 IOException (java.io.IOException)2 TestOnly (org.jetbrains.annotations.TestOnly)1 Test (org.junit.Test)1 Timeout (org.junit.jupiter.api.Timeout)1 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)1