use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.
the class DownloadActionTest method shouldFailAfterFourthTryWhenDownloadFails.
@Test
public void shouldFailAfterFourthTryWhenDownloadFails() throws Exception {
try (LogFixture logging = logFixtureFor(DownloadAction.class, Level.DEBUG)) {
FailSometimesHttpService httpService = new FailSometimesHttpService(99);
try {
new DownloadAction(httpService, new StubGoPublisher(), clock).perform("foo", fetchHandler);
fail("Expected to throw exception after four tries");
} catch (Exception e) {
assertThat(httpService.timesCalled, is(4));
shouldHaveLogged(logging, Level.ERROR, "Giving up fetching resource 'foo'. Tried 4 times and failed.");
}
}
}
use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.
the class AgentProcessParentImplTest method shouldLogInterruptOnAgentProcess.
@Test
public void shouldLogInterruptOnAgentProcess() throws InterruptedException {
final List<String> cmd = new ArrayList<>();
try (LogFixture logFixture = logFixtureFor(AgentProcessParentImpl.class, Level.DEBUG)) {
Process subProcess = mockProcess();
when(subProcess.waitFor()).thenThrow(new InterruptedException("bang bang!"));
AgentProcessParentImpl bootstrapper = createBootstrapper(cmd, subProcess);
int returnCode = bootstrapper.run("bootstrapper_version", "bar", getURLGenerator(), new HashMap<>(), context());
assertThat(returnCode, is(0));
assertThat(logFixture.contains(Level.ERROR, "Agent was interrupted. Terminating agent and respawning. java.lang.InterruptedException: bang bang!"), is(true));
verify(subProcess).destroy();
}
}
use of com.thoughtworks.go.util.LogFixture 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 = ArrayUtil.join(logFixture.getMessages());
assertThat(logs, containsString("not-not-not-exist ******"));
assertThat(logs, not(containsString("topsecret")));
}
}
use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.
the class JobRerunScheduleServiceTest method shouldMarkResultIfScheduleFailsForUnexpectedReason.
@Test
public void shouldMarkResultIfScheduleFailsForUnexpectedReason() {
PipelineConfig mingleConfig = PipelineConfigMother.createPipelineConfig("mingle", "build", "unit", "functional");
Pipeline pipeline = PipelineMother.passedPipelineInstance("mingle", "build", "unit");
Stage firstStage = pipeline.getFirstStage();
stub(mingleConfig, pipeline, firstStage);
//leads to null pointer exception
schedulingChecker = mock(SchedulingCheckerService.class);
doThrow(new NullPointerException("The whole world is a big null.")).when(schedulingChecker).canSchedule(any(OperationResult.class));
service = new ScheduleService(goConfigService, pipelineService, stageService, schedulingChecker, mock(PipelineScheduledTopic.class), mock(PipelineDao.class), mock(StageDao.class), mock(StageOrderService.class), securityService, pipelineScheduleQueue, jobInstanceService, mock(JobInstanceDao.class), mock(AgentAssignment.class), environmentConfigService, lockService, serverHealthService, txnTemplate, mock(AgentService.class), null, null, null, null, null, schedulingPerformanceLogger, null);
HttpOperationResult result = new HttpOperationResult();
try (LogFixture logFixture = logFixtureFor(ScheduleService.class, Level.DEBUG)) {
Stage stage = service.rerunJobs(firstStage, a("unit"), result);
assertThat(logFixture.contains(Level.ERROR, "Job rerun request for job(s) [unit] could not be completed because of unexpected failure. Cause: The whole world is a big null."), is(true));
assertThat(stage, is(nullValue()));
assertThat(result.httpCode(), is(400));
assertThat(result.message(), is("Job rerun request for job(s) [unit] could not be completed because of unexpected failure. Cause: The whole world is a big null."));
}
}
use of com.thoughtworks.go.util.LogFixture in project gocd by gocd.
the class DefaultPluginLoggingServiceIntegrationTest method shouldNotLogPluginMessagesToRootLogger.
@Test
public void shouldNotLogPluginMessagesToRootLogger() throws Exception {
try (LogFixture fixture = logFixtureForRootLogger(Level.INFO)) {
DefaultPluginLoggingService service = new DefaultPluginLoggingService(systemEnvironment);
service.info(pluginID(1), "LoggingClass", "this-message-should-not-go-to-root-logger");
String failureMessage = "Expected no messages to be logged to root logger. Found: " + Arrays.toString(fixture.getMessages());
assertThat(failureMessage, fixture.getMessages().length, is(0));
}
}
Aggregations