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();
}
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();
}
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")));
}
}
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> ..."));
}
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));
}
Aggregations