use of com.facebook.buck.test.TestResults in project buck by facebook.
the class TestRunningTest method testRunAlwaysRequiredIfEnvironmentOverridesPresent.
@Test
public void testRunAlwaysRequiredIfEnvironmentOverridesPresent() throws Exception {
ExecutionContext executionContext = TestExecutionContext.newBuilder().setDebugEnabled(false).build();
FakeTestRule testRule = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of()) {
@Override
public boolean hasTestResultFiles() {
return true;
}
};
TestRuleKeyFileHelper testRuleKeyFileHelper = createNiceMock(TestRuleKeyFileHelper.class);
expect(testRuleKeyFileHelper.isRuleKeyInDir(testRule)).andReturn(true).times(1);
CachingBuildEngine cachingBuildEngine = createMock(CachingBuildEngine.class);
BuildResult result = BuildResult.success(testRule, MATCHING_RULE_KEY, CacheResult.miss());
expect(cachingBuildEngine.getBuildRuleResult(BuildTargetFactory.newInstance("//:lulz"))).andReturn(result).times(1);
replay(cachingBuildEngine, testRuleKeyFileHelper);
assertFalse("Test will normally not be rerun", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED, Callables.<TestResults>returning(null), /* running with test selectors */
false, /* hasEnvironmentOverrides */
false));
assertTrue("Test will be rerun when environment overrides are present", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED, Callables.<TestResults>returning(null), /* running with test selectors */
false, /* hasEnvironmentOverrides */
true));
verify(cachingBuildEngine, testRuleKeyFileHelper);
}
use of com.facebook.buck.test.TestResults in project buck by facebook.
the class TestRunningTest method testIsTestRunRequiredForTestBuiltFromCacheIfHasTestResultFiles.
@Test
public void testIsTestRunRequiredForTestBuiltFromCacheIfHasTestResultFiles() throws IOException, ExecutionException, InterruptedException {
ExecutionContext executionContext = TestExecutionContext.newInstance();
assertFalse(executionContext.isDebugEnabled());
FakeTestRule testRule = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of());
CachingBuildEngine cachingBuildEngine = createMock(CachingBuildEngine.class);
BuildResult result = BuildResult.success(testRule, FETCHED_FROM_CACHE, CacheResult.hit("dir"));
expect(cachingBuildEngine.getBuildRuleResult(BuildTargetFactory.newInstance("//:lulz"))).andReturn(result);
replay(cachingBuildEngine);
assertTrue("A cache hit updates the build artifact but not the test results. " + "Therefore, the test should be re-run to ensure the test results are up to date.", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, createMock(TestRuleKeyFileHelper.class), TestRunningOptions.TestResultCacheMode.ENABLED, Callables.<TestResults>returning(null), /* running with test selectors */
false, /* hasEnvironmentOverrides */
false));
verify(cachingBuildEngine);
}
use of com.facebook.buck.test.TestResults in project buck by facebook.
the class TestRunningTest method whenAllTestsAreSeparateTestsRunInOrder.
@Test
public void whenAllTestsAreSeparateTestsRunInOrder() throws Exception {
CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().build();
AtomicInteger atomicExecutionOrder = new AtomicInteger(0);
ExecutionOrderAwareFakeStep separateTestStep1 = new ExecutionOrderAwareFakeStep("teststep1", "teststep1", 0, atomicExecutionOrder);
final TestResults fakeTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.SUCCESS, 5000, null, null, null, null)))));
BuildTarget separateTest1Target = BuildTargetFactory.newInstance("//:test1");
FakeTestRule separateTest1 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest1Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep1OutputDir")), // runTestSeparately
true, ImmutableList.of(separateTestStep1), () -> fakeTestResults);
ExecutionOrderAwareFakeStep separateTestStep2 = new ExecutionOrderAwareFakeStep("teststep2", "teststep2", 0, atomicExecutionOrder);
BuildTarget separateTest2Target = BuildTargetFactory.newInstance("//:test2");
FakeTestRule separateTest2 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest2Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep2OutputDir")), // runTestSeparately
true, ImmutableList.of(separateTestStep2), () -> fakeTestResults);
ExecutionOrderAwareFakeStep separateTestStep3 = new ExecutionOrderAwareFakeStep("teststep3", "teststep3", 0, atomicExecutionOrder);
BuildTarget separateTest3Target = BuildTargetFactory.newInstance("//:test3");
FakeTestRule separateTest3 = new FakeTestRule(new FakeBuildRuleParamsBuilder(separateTest3Target).build(), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSet.of(), Optional.of(Paths.get("separateTestStep3OutputDir")), // runTestSeparately
true, ImmutableList.of(separateTestStep3), () -> fakeTestResults);
// We explicitly use an actual thread pool here; the logic should ensure the
// separate tests are run in the correct order.
ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(3));
FakeBuildEngine fakeBuildEngine = new FakeBuildEngine(ImmutableMap.of(separateTest1Target, BuildResult.success(separateTest1, BUILT_LOCALLY, CacheResult.miss()), separateTest2Target, BuildResult.success(separateTest2, BUILT_LOCALLY, CacheResult.miss()), separateTest3Target, BuildResult.success(separateTest3, BUILT_LOCALLY, CacheResult.miss())), ImmutableMap.of(separateTest1Target, new RuleKey("00"), separateTest2Target, new RuleKey("00"), separateTest3Target, new RuleKey("00")));
ExecutionContext fakeExecutionContext = TestExecutionContext.newInstance();
DefaultStepRunner stepRunner = new DefaultStepRunner();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
int ret = TestRunning.runTests(commandRunnerParams, ImmutableList.of(separateTest1, separateTest2, separateTest3), fakeExecutionContext, DEFAULT_OPTIONS, service, fakeBuildEngine, stepRunner, new SourcePathResolver(ruleFinder), ruleFinder);
assertThat(ret, equalTo(0));
assertThat(separateTestStep1.getExecutionBeginOrder(), equalTo(Optional.of(0)));
assertThat(separateTestStep1.getExecutionEndOrder(), equalTo(Optional.of(1)));
assertThat(separateTestStep2.getExecutionBeginOrder(), equalTo(Optional.of(2)));
assertThat(separateTestStep2.getExecutionEndOrder(), equalTo(Optional.of(3)));
assertThat(separateTestStep3.getExecutionBeginOrder(), equalTo(Optional.of(4)));
assertThat(separateTestStep3.getExecutionEndOrder(), equalTo(Optional.of(5)));
}
use of com.facebook.buck.test.TestResults in project buck by facebook.
the class TestResultFormatterTest method shouldOutputLogLinesOfFailingTest.
@Test
public void shouldOutputLogLinesOfFailingTest() throws IOException {
TestResultFormatter formatter = createFormatterWithMaxLogLines(10);
TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(failingTest));
Files.write(logPath, ImmutableList.of("This is a debug log", "Here's another one"), StandardCharsets.UTF_8);
TestResults results = TestResults.builder().setBuildTarget(BuildTargetFactory.newInstance("//foo:bar")).setTestCases(ImmutableList.of(summary)).addTestLogPaths(logPath).build();
ImmutableList.Builder<String> builder = ImmutableList.builder();
formatter.reportResult(builder, results);
String expected = String.format(Joiner.on('\n').join("FAIL 200ms 0 Passed 0 Skipped 1 Failed com.example.FooTest", "FAILURE %s %s: %s", "%s", "====TEST LOGS====", "Logs from log.txt:", "This is a debug log", "Here's another one"), failingTest.getTestCaseName(), failingTest.getTestName(), failingTest.getMessage(), stackTrace);
assertEquals(expected, toString(builder));
}
use of com.facebook.buck.test.TestResults in project buck by facebook.
the class TestResultFormatterTest method shouldOutputTruncatedLogLinesOfFailingTest.
@Test
public void shouldOutputTruncatedLogLinesOfFailingTest() throws IOException {
TestResultFormatter formatter = createFormatterWithMaxLogLines(3);
TestCaseSummary summary = new TestCaseSummary("com.example.FooTest", ImmutableList.of(failingTest));
Files.write(logPath, ImmutableList.of("This log won't appear", "This one will", "Another one", "Should be last"), StandardCharsets.UTF_8);
TestResults results = TestResults.builder().setBuildTarget(BuildTargetFactory.newInstance("//foo:bar")).setTestCases(ImmutableList.of(summary)).addTestLogPaths(logPath).build();
ImmutableList.Builder<String> builder = ImmutableList.builder();
formatter.reportResult(builder, results);
String expected = String.format(Joiner.on('\n').join("FAIL 200ms 0 Passed 0 Skipped 1 Failed com.example.FooTest", "FAILURE %s %s: %s", "%s", "====TEST LOGS====", "Last 3 test log lines from log.txt:", "This one will", "Another one", "Should be last"), failingTest.getTestCaseName(), failingTest.getTestName(), failingTest.getMessage(), stackTrace);
assertEquals(expected, toString(builder));
}
Aggregations