use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class DaemonIntegrationTest method whenClientDisconnectionDetectedThenBuildIsInterrupted.
/**
* 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 whenClientDisconnectionDetectedThenBuildIsInterrupted() throws InterruptedException, IOException {
// Sub process interruption not supported on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
// Stream timeout > test timeout.
final long timeoutMillis = 2000;
// Disconnect before test timeout.
final long disconnectMillis = 100;
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.createDisconnectionStream(disconnectMillis), 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 DaemonIntegrationTest method whenClientDisconnectionDetectedThenTestIsInterrupted.
/**
* This verifies that a client disconnection will be detected by a Nailgun
* NGInputStream reading from an empty heartbeat stream and that the generated
* InterruptedException will interrupt command execution causing it to fail.
*/
@Test
public void whenClientDisconnectionDetectedThenTestIsInterrupted() throws InterruptedException, IOException {
// Sub process interruption not supported on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
// Stream timeout > test timeout.
final long timeoutMillis = 2000;
// Disconnect before test timeout.
final long disconnectMillis = 100;
final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp);
workspace.setUp();
// Start with an input stream that sends heartbeats at a regular rate.
final DelegatingInputStream inputStream = new DelegatingInputStream(TestContext.createHeartBeatStream(timeoutMillis / 10));
// Build an NGContext connected to an NGInputStream reading from stream that will timeout.
try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), inputStream, timeoutMillis)) {
ProcessResult result = workspace.runBuckdCommand(context, new CapturingPrintStream() {
@Override
public void println(String x) {
if (x.contains("TESTING //:test")) {
// When tests start running, make the heartbeat stream simulate a disconnection.
inputStream.setDelegate(TestContext.createDisconnectionStream(disconnectMillis));
}
super.println(x);
}
}, "test", "//:test");
result.assertFailure();
assertThat(result.getStderr(), containsString("InterruptedException"));
}
}
use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class WebServerBuckEventListenerTest method hasBuckTestStartedThenEventsCalled.
@Test
@Ignore
public void hasBuckTestStartedThenEventsCalled() throws IOException, InterruptedException {
final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "buck_events/test", 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);
//Individual test started
//This target has only 1 test
webServerBuckEventListener.testAwaitingResults(anyObject(IndividualTestEvent.Started.class));
EasyMock.expectLastCall().times(1);
//Individual test finished
webServerBuckEventListener.testResultsAvailable(anyObject(IndividualTestEvent.Finished.class));
EasyMock.expectLastCall().times(1);
//Test started
webServerBuckEventListener.testRunStarted(anyObject(TestRunEvent.Started.class));
EasyMock.expectLastCall().times(1);
//Test finished
webServerBuckEventListener.testRunCompleted(anyObject(TestRunEvent.Finished.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(), "test", "//:simple_test");
build.assertSuccess();
verify(webServerBuckEventListener);
}
use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class DaemonIntegrationTest method whenClientTimeoutDetectedThenMainThreadIsInterrupted.
/**
* Verifies that a client timeout will be detected by a Nailgun
* NGInputStream reading from a blocking heartbeat stream.
*/
@Test(expected = InterruptedException.class)
public void whenClientTimeoutDetectedThenMainThreadIsInterrupted() throws InterruptedException, IOException {
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 a stream that will timeout.
Thread.currentThread().setName("Test");
try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), TestContext.createHeartBeatStream(intervalMillis), timeoutMillis)) {
context.addClientListener(Thread.currentThread()::interrupt);
Thread.sleep(1000);
fail("Should have been interrupted.");
}
}
use of com.facebook.buck.testutil.integration.TestContext in project buck by facebook.
the class DaemonIntegrationTest method whenClientTimeoutDetectedThenTestIsInterrupted.
/**
* This verifies that a client disconnection will be detected by a Nailgun
* NGInputStream reading from an empty heartbeat stream and that the generated
* InterruptedException will interrupt command execution causing it to fail.
*/
@Test
public void whenClientTimeoutDetectedThenTestIsInterrupted() throws InterruptedException, IOException {
// Sub process interruption not supported on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
final long timeoutMillis = 100;
final ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "exclusive_execution", tmp);
workspace.setUp();
// Start with an input stream that sends heartbeats at a regular rate.
final DelegatingInputStream inputStream = new DelegatingInputStream(TestContext.createHeartBeatStream(timeoutMillis / 10));
// Build an NGContext connected to an NGInputStream reading from stream that will timeout.
try (TestContext context = new TestContext(ImmutableMap.copyOf(System.getenv()), inputStream, timeoutMillis)) {
ProcessResult result = workspace.runBuckdCommand(context, new CapturingPrintStream() {
@Override
public void println(String x) {
if (x.contains("TESTING //:test")) {
// When tests start running, make the heartbeat stream simulate a disconnection.
inputStream.setDelegate(TestContext.createDisconnectionStream(2 * timeoutMillis));
}
super.println(x);
}
}, "test", "//:test");
result.assertFailure();
assertThat(result.getStderr(), containsString("InterruptedException"));
}
}
Aggregations