Search in sources :

Example 6 with RunIf

use of com.googlecode.junit.ext.RunIf in project gocd by gocd.

the class BuildSessionCancelingTest method cancelTaskShouldBeProcessedBeforeKillChildProcess.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void cancelTaskShouldBeProcessedBeforeKillChildProcess() throws InterruptedException {
    final BuildSession buildSession = newBuildSession();
    final BuildCommand printSubProcessCount = exec("/bin/bash", "-c", "pgrep -P " + new JavaSysMon().currentPid() + " | wc -l");
    Thread buildingThread = new Thread(new Runnable() {

        @Override
        public void run() {
            buildSession.build(compose(compose(execSleepScript(50), echo("after sleep")).setOnCancel(printSubProcessCount)));
        }
    });
    buildingThread.start();
    waitUntilSubProcessExists(execSleepScriptProcessCommand(), true);
    assertTrue(buildInfo(), buildSession.cancel(30, TimeUnit.SECONDS));
    waitUntilSubProcessExists(execSleepScriptProcessCommand(), false);
    assertThat(Integer.parseInt(console.lastLine().trim()), greaterThan(0));
    buildingThread.join();
}
Also used : JavaSysMon(com.jezhumble.javasysmon.JavaSysMon) BuildCommand(com.thoughtworks.go.domain.BuildCommand) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 7 with RunIf

use of com.googlecode.junit.ext.RunIf in project gocd by gocd.

the class BuildSessionCancelingTest method cancelShouldProcessOnCancelCommandOfCommandThatIsRunning.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, WINDOWS })
public void cancelShouldProcessOnCancelCommandOfCommandThatIsRunning() throws InterruptedException {
    final BuildSession buildSession = newBuildSession();
    Thread buildingThread = new Thread(new Runnable() {

        @Override
        public void run() {
            buildSession.build(compose(compose(execSleepScript(50).setOnCancel(echo("exec canceled")), echo("after sleep")).setOnCancel(echo("inner oncancel"))).setOnCancel(echo("outter oncancel")));
        }
    });
    buildingThread.start();
    waitUntilSubProcessExists(execSleepScriptProcessCommand(), true);
    assertTrue(buildInfo(), buildSession.cancel(30, TimeUnit.SECONDS));
    waitUntilSubProcessExists(execSleepScriptProcessCommand(), false);
    JavaSysMon javaSysMon = new JavaSysMon();
    final boolean[] exists = { false };
    javaSysMon.visitProcessTree(javaSysMon.currentPid(), new ProcessVisitor() {

        @Override
        public boolean visit(OsProcess osProcess, int i) {
            String command = osProcess.processInfo().getName();
            if (execSleepScriptProcessCommand().equals(command)) {
                exists[0] = true;
            }
            return false;
        }
    });
    assertThat(exists[0], is(false));
    assertThat(buildInfo(), getLast(statusReporter.results()), is(Cancelled));
    assertThat(buildInfo(), console.output(), not(containsString("after sleep")));
    assertThat(buildInfo(), console.output(), containsString("exec canceled"));
    assertThat(buildInfo(), console.output(), containsString("inner oncancel"));
    assertThat(buildInfo(), console.output(), containsString("outter oncancel"));
    buildingThread.join();
}
Also used : OsProcess(com.jezhumble.javasysmon.OsProcess) JavaSysMon(com.jezhumble.javasysmon.JavaSysMon) ProcessVisitor(com.jezhumble.javasysmon.ProcessVisitor) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 8 with RunIf

use of com.googlecode.junit.ext.RunIf in project gocd by gocd.

the class ExecCommandExecutorTest method shouldNotLeakSecretsToLog.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { DO_NOT_RUN_ON, OSChecker.WINDOWS })
public void shouldNotLeakSecretsToLog() {
    try (LogFixture logFixture = logFixtureFor(ExecCommandExecutor.class, Level.DEBUG)) {
        runBuild(compose(secret("topsecret"), exec("not-not-not-exist", "topsecret")), Failed);
        String logs = logFixture.getLog();
        assertThat(logs, containsString("not-not-not-exist ******"));
        assertThat(logs, not(containsString("topsecret")));
    }
}
Also used : LogFixture(com.thoughtworks.go.util.LogFixture) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 9 with RunIf

use of com.googlecode.junit.ext.RunIf in project gocd by gocd.

the class BuildWorkTest method nantTest.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { EnhancedOSChecker.WINDOWS })
public void nantTest() throws Exception {
    buildWork = (BuildWork) getWork(NANT, PIPELINE_NAME);
    buildWork.doWork(agentIdentifier, buildRepository, artifactManipulator, environmentVariableContext, new AgentRuntimeInfo(agentIdentifier, AgentRuntimeStatus.Idle, currentWorkingDirectory(), "cookie", false), packageRepositoryExtension, scmExtension, taskExtension);
    assertThat(artifactManipulator.consoleOut(), containsString("Usage : NAnt [options] <target> <target> ..."));
}
Also used : AgentRuntimeInfo(com.thoughtworks.go.server.service.AgentRuntimeInfo) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 10 with RunIf

use of com.googlecode.junit.ext.RunIf in project gocd by gocd.

the class FileUtilTest method shouldCreateFileURIForFileOnWindows.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { EnhancedOSChecker.WINDOWS })
public void shouldCreateFileURIForFileOnWindows() {
    assertThat(FileUtil.toFileURI(new File("c:\\foo")).startsWith("file:///c:/foo"), is(true));
    assertThat(FileUtil.toFileURI(new File("c:\\a dir with spaces\\foo")).startsWith("file:///c:/a%20dir%20with%20spaces/foo"), is(true));
}
Also used : File(java.io.File) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Aggregations

RunIf (com.googlecode.junit.ext.RunIf)17 Test (org.junit.Test)15 File (java.io.File)7 AgentRuntimeInfo (com.thoughtworks.go.server.service.AgentRuntimeInfo)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JavaSysMon (com.jezhumble.javasysmon.JavaSysMon)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 OsProcess (com.jezhumble.javasysmon.OsProcess)1 ProcessVisitor (com.jezhumble.javasysmon.ProcessVisitor)1 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)1 BuildCommand (com.thoughtworks.go.domain.BuildCommand)1 Pipeline (com.thoughtworks.go.domain.Pipeline)1 RunIfConfigs (com.thoughtworks.go.domain.RunIfConfigs)1 ServerBackup (com.thoughtworks.go.server.domain.ServerBackup)1 LogFixture (com.thoughtworks.go.util.LogFixture)1 TimeProvider (com.thoughtworks.go.util.TimeProvider)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1