use of org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig in project pnc by project-ncl.
the class LivenessProbeTest method shouldFailTheBuildWhenAgentIsNotResponding.
@Test
public void shouldFailTheBuildWhenAgentIsNotResponding() throws InterruptedException, BuildDriverException {
TermdBuildDriverModuleConfig buildDriverModuleConfig = mock(TermdBuildDriverModuleConfig.class);
doReturn(200L).when(buildDriverModuleConfig).getLivenessProbeFrequencyMillis();
doReturn(500L).when(buildDriverModuleConfig).getLivenessFailTimeoutMillis();
ClientMockFactory buildAgentClientMockFactory = new ClientMockFactory();
TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, buildAgentClientMockFactory);
BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
RunningEnvironment runningEnvironment = mock(RunningEnvironment.class);
doReturn(Paths.get("")).when(runningEnvironment).getWorkingDirectory();
doReturn(new DebugData(false)).when(runningEnvironment).getDebugData();
doReturn("http://localhost/").when(runningEnvironment).getInternalBuildAgentUrl();
doReturn(runningEnvironment).when(buildExecution).getRunningEnvironment();
BlockingQueue<Throwable> result = new ArrayBlockingQueue(1);
Consumer<CompletedBuild> onComplete = (completedBuild) -> Assert.fail("Build should complete with error.");
Consumer<Throwable> onError = (throwable) -> {
try {
result.put(throwable);
} catch (InterruptedException e) {
Assert.fail("Error in the test. Unable to add the result to queue.");
}
};
// when
RunningBuild runningBuild = driver.startProjectBuild(buildExecution, runningEnvironment, onComplete, onError);
// then
Throwable throwable = result.poll(1, TimeUnit.SECONDS);
Assert.assertNotNull("It should complete with an exception.", throwable);
Assert.assertEquals("Build Agent has gone away.", throwable.getMessage());
}
use of org.jboss.pnc.common.json.moduleconfig.TermdBuildDriverModuleConfig in project pnc by project-ncl.
the class DebugInContainerTest method shouldEnableSshWhenBuildFails.
@Test
public void shouldEnableSshWhenBuildFails() throws InterruptedException, BuildDriverException {
TermdBuildDriverModuleConfig buildDriverModuleConfig = mock(TermdBuildDriverModuleConfig.class);
doReturn(1000L).when(buildDriverModuleConfig).getLivenessProbeFrequencyMillis();
doReturn(5000L).when(buildDriverModuleConfig).getLivenessFailTimeoutMillis();
doReturn(5000).when(buildDriverModuleConfig).getFileTransferReadTimeout();
ClientMockFactory buildAgentClientFactory = new ClientMockFactory();
TermdBuildDriver driver = new TermdBuildDriver(systemConfig, buildDriverModuleConfig, buildAgentClientFactory);
BuildExecutionSession buildExecution = mock(BuildExecutionSession.class);
BuildExecutionConfiguration buildExecutionConfiguration = mock(BuildExecutionConfiguration.class);
doReturn(buildExecutionConfiguration).when(buildExecution).getBuildExecutionConfiguration();
RunningEnvironment runningEnvironment = mock(RunningEnvironment.class);
doReturn(Paths.get("")).when(runningEnvironment).getWorkingDirectory();
doReturn(new DebugData(true)).when(runningEnvironment).getDebugData();
doReturn("http://localhost/").when(runningEnvironment).getInternalBuildAgentUrl();
doReturn(runningEnvironment).when(buildExecution).getRunningEnvironment();
BlockingQueue<CompletedBuild> result = new ArrayBlockingQueue(1);
Consumer<CompletedBuild> onComplete = (completedBuild) -> {
try {
result.put(completedBuild);
} catch (InterruptedException e) {
Assert.fail("Unable to consume build result.");
}
};
Consumer<Throwable> onError = (throwable) -> Assert.fail("Build should fail without system error.");
// when
RunningBuild runningBuild = driver.startProjectBuild(buildExecution, runningEnvironment, onComplete, onError);
// wait to start waiting for completion and start liveness probe
Thread.sleep(500);
buildAgentClientFactory.getOnStatusUpdate().accept(TaskStatusUpdateEvent.newBuilder().newStatus(Status.FAILED).build());
// then
CompletedBuild completedBuild = result.poll(3, TimeUnit.SECONDS);
Assert.assertNotNull("Missing build result.", completedBuild);
Assert.assertEquals("The build should fail.", BuildStatus.FAILED, completedBuild.getBuildResult().getBuildStatus());
List<Object> executedCommands = buildAgentClientFactory.getBuildAgentClient().getExecutedCommands();
logger.info("Executed commands {}.", executedCommands);
Assert.assertEquals(2, executedCommands.size());
Assertions.assertThat(executedCommands).anySatisfy(c -> ((String) c).contains("startSshd.sh"));
}
Aggregations