use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class DaemonIntegrationTest method createRunnableCommand.
private Runnable createRunnableCommand(final int expectedExitCode, final String... args) {
return () -> {
try {
Main main = new Main(new CapturingPrintStream(), new CapturingPrintStream(), new ByteArrayInputStream("".getBytes("UTF-8")));
int exitCode = main.runMainWithExitCode(new BuildId(), tmp.getRoot(), Optional.of(new TestContext()), ImmutableMap.copyOf(System.getenv()), CommandMode.TEST, WatchmanWatcher.FreshInstanceAction.NONE, System.nanoTime(), args);
assertEquals("Unexpected exit code.", expectedExitCode, exitCode);
} catch (IOException e) {
fail("Should not throw exception.");
Throwables.throwIfUnchecked(e);
} catch (InterruptedException e) {
fail("Should not throw exception.");
Thread.currentThread().interrupt();
}
};
}
use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class DaemonIntegrationTest method whenClientTimeoutDetectedThenBuildIsInterrupted.
/**
* This verifies that a client timeout will be detected by a Nailgun
* NGInputStream reading from an empty heartbeat stream and that the generated
* InterruptedException will cause command execution to fail after timeout.
*/
@Test
public void whenClientTimeoutDetectedThenBuildIsInterrupted() throws InterruptedException, IOException {
// Sub process interruption not supported on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
final long timeoutMillis = 100;
// Interval > timeout to trigger disconnection.
final long intervalMillis = timeoutMillis * 2;
final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp);
workspace.setUp();
// Build an NGContext connected to an NGInputStream reading from stream that will timeout.
try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), TestContext.createHeartBeatStream(intervalMillis), timeoutMillis)) {
ProcessResult result = workspace.runBuckdCommand(context, "build", "//:sleep");
result.assertFailure();
assertThat(result.getStderr(), containsString("InterruptedException"));
}
}
use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class ActionGraphCacheIntegrationTest method specifyingSkipActionGraphCacheDoesNotInvalidateTheActionGraphCache.
@Test
public void specifyingSkipActionGraphCacheDoesNotInvalidateTheActionGraphCache() throws IOException {
try (TestContext context = new TestContext()) {
workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
assertEquals("Should be a fresh daemon, so the ActionGraph cache should be empty.", ActionGraphCacheStatus.MISS_CACHE_EMPTY, getActionGraphCacheStatus());
workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
assertEquals("Rebuilding the rule should hit the cache.", ActionGraphCacheStatus.HIT, getActionGraphCacheStatus());
workspace.runBuckdCommand(context, "build", "//:pretend_this_is_a_cheap_rule").assertSuccess();
assertEquals("Building a different rule as a non-oneoff should invalidate the cache.", ActionGraphCacheStatus.MISS_TARGET_GRAPH_MISMATCH, getActionGraphCacheStatus());
workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
assertEquals("Building a different rule as a non-oneoff should invalidate the cache again.", ActionGraphCacheStatus.MISS_TARGET_GRAPH_MISMATCH, getActionGraphCacheStatus());
workspace.runBuckdCommand(context, "build", "--config", "client.skip-action-graph-cache=true", "//:pretend_this_is_a_cheap_rule").assertSuccess();
assertEquals("Building a different rule as a oneoff will still be a mismatch.", ActionGraphCacheStatus.MISS_TARGET_GRAPH_MISMATCH, getActionGraphCacheStatus());
workspace.runBuckdCommand(context, "build", "//:pretend_this_is_an_expensive_rule").assertSuccess();
assertEquals("The ActionGraph for the expensive rule should still be in cache.", ActionGraphCacheStatus.HIT, getActionGraphCacheStatus());
}
}
use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class WebServerBuckEventListenerTest method hasBuckCompilerErrorOccurredThenEventsCalled.
@Test
@Ignore
public void hasBuckCompilerErrorOccurredThenEventsCalled() throws IOException, InterruptedException {
final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "buck_events/compiler_error", tmp);
workspace.setUp();
WebServerBuckEventListener webServerBuckEventListener = createMock(WebServerBuckEventListener.class);
//Build started
webServerBuckEventListener.buildStarted(anyObject(BuildEvent.Started.class));
EasyMock.expectLastCall().times(1);
//Build progress Event
webServerBuckEventListener.buildProgressUpdated(anyObject(ProgressEvent.BuildProgressUpdated.class));
EasyMock.expectLastCall().atLeastOnce();
//Build finished
webServerBuckEventListener.buildFinished(anyObject(BuildEvent.Finished.class));
EasyMock.expectLastCall().times(1);
//Parse started
webServerBuckEventListener.parseStarted(anyObject(ParseEvent.Started.class));
EasyMock.expectLastCall().times(1);
//Parse progress Event
webServerBuckEventListener.parsingProgressUpdated(anyObject(ProgressEvent.ParsingProgressUpdated.class));
EasyMock.expectLastCall().atLeastOnce();
//Parse finished
webServerBuckEventListener.parseFinished(anyObject(ParseEvent.Finished.class));
EasyMock.expectLastCall().times(1);
//Compiler error
webServerBuckEventListener.compilerErrorEvent(anyObject(CompilerErrorEvent.class));
EasyMock.expectLastCall().times(1);
//Console event
webServerBuckEventListener.consoleEvent(anyObject(ConsoleEvent.class));
EasyMock.expectLastCall().times(1);
//Output trace
webServerBuckEventListener.outputTrace(anyObject(BuildId.class));
EasyMock.expectLastCall().times(1);
EasyMock.replay(webServerBuckEventListener);
ProjectWorkspace.ProcessResult build = workspace.runBuckdCommand(new TestContext(), "build", "//:broken");
build.assertFailure();
verify(webServerBuckEventListener);
}
use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class WebServerBuckEventListenerTest method hasBuckBuildStartedThenEventsCalled.
@Test
@Ignore
public void hasBuckBuildStartedThenEventsCalled() throws IOException, InterruptedException {
final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "buck_events", tmp);
workspace.setUp();
WebServerBuckEventListener webServerBuckEventListener = createMock(WebServerBuckEventListener.class);
//Build started
webServerBuckEventListener.buildStarted(anyObject(BuildEvent.Started.class));
EasyMock.expectLastCall().times(1);
//Build progress Event
webServerBuckEventListener.buildProgressUpdated(anyObject(ProgressEvent.BuildProgressUpdated.class));
EasyMock.expectLastCall().atLeastOnce();
//Build finished
webServerBuckEventListener.buildFinished((BuildEvent.Finished) anyObject());
EasyMock.expectLastCall().times(1);
//Parse started
webServerBuckEventListener.parseStarted(anyObject(ParseEvent.Started.class));
EasyMock.expectLastCall().times(1);
//Parse progress Event
webServerBuckEventListener.parsingProgressUpdated((ProgressEvent.ParsingProgressUpdated) anyObject());
EasyMock.expectLastCall().atLeastOnce();
//Parse finished
webServerBuckEventListener.parseFinished((ParseEvent.Finished) anyObject());
EasyMock.expectLastCall().times(1);
//Output trace
webServerBuckEventListener.outputTrace(anyObject(BuildId.class));
EasyMock.expectLastCall().times(1);
EasyMock.replay(webServerBuckEventListener);
ProjectWorkspace.ProcessResult build = workspace.runBuckdCommand(new TestContext(), "build", "//:foo");
build.assertSuccess();
verify(webServerBuckEventListener);
}
Aggregations