Search in sources :

Example 61 with EventBus

use of com.google.common.eventbus.EventBus in project buck by facebook.

the class WatchmanWatcherTest method whenWatchmanInterruptedThenOverflowEventGenerated.

@Test
public void whenWatchmanInterruptedThenOverflowEventGenerated() throws IOException, InterruptedException {
    String message = "Boo!";
    Capture<WatchEvent<Path>> eventCapture = newCapture();
    EventBus eventBus = createStrictMock(EventBus.class);
    eventBus.post(capture(eventCapture));
    replay(eventBus);
    WatchmanWatcher watcher = createWatcher(eventBus, new FakeWatchmanClient(0, /* queryElapsedTimeNanos */
    ImmutableMap.of(FAKE_UUID_QUERY, ImmutableMap.of()), new InterruptedException(message)), 10000);
    try {
        watcher.postEvents(BuckEventBusFactory.newInstance(new FakeClock(0)), WatchmanWatcher.FreshInstanceAction.NONE);
    } catch (InterruptedException e) {
        assertEquals("Should be test interruption.", e.getMessage(), message);
    }
    verify(eventBus);
    assertTrue(Thread.currentThread().isInterrupted());
    assertEquals("Should be overflow event.", StandardWatchEventKinds.OVERFLOW, eventCapture.getValue().kind());
}
Also used : FakeWatchmanClient(com.facebook.buck.io.FakeWatchmanClient) FakeClock(com.facebook.buck.timing.FakeClock) WatchEvent(java.nio.file.WatchEvent) BuckEventBus(com.facebook.buck.event.BuckEventBus) EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 62 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class BuildViewTest method testMultipleRootCauseReporting.

@Test
public void testMultipleRootCauseReporting() throws Exception {
    scratch.file("gp/BUILD", "sh_library(name = 'gp', deps = ['//p:p'])");
    scratch.file("p/BUILD", "sh_library(name = 'p', deps = ['//c1:not', '//c2:not'])");
    scratch.file("c1/BUILD");
    scratch.file("c2/BUILD");
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    LoadingFailureRecorder recorder = new LoadingFailureRecorder();
    eventBus.register(recorder);
    AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//gp");
    assertThat(result.hasError()).isTrue();
    assertThat(recorder.events).hasSize(2);
    assertTrue(recorder.events.toString(), recorder.events.contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//c1:not"))));
    assertThat(recorder.events).contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//c2:not")));
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 63 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class BuildViewTest method testRootCauseReportingFileSymlinks.

/**
   * Tests that skyframe reports the root cause as being the target that depended on the symlink
   * cycle.
   */
@Test
public void testRootCauseReportingFileSymlinks() throws Exception {
    scratch.file("gp/BUILD", "sh_library(name = 'gp', deps = ['//p'])");
    scratch.file("p/BUILD", "sh_library(name = 'p', deps = ['//c'])");
    scratch.file("c/BUILD", "sh_library(name = 'c', deps = [':c1', ':c2'])", "sh_library(name = 'c1', deps = ['//cycles1'])", "sh_library(name = 'c2', deps = ['//cycles2'])");
    Path cycles1BuildFilePath = scratch.file("cycles1/BUILD", "sh_library(name = 'cycles1', srcs = glob(['*.sh']))");
    Path cycles2BuildFilePath = scratch.file("cycles2/BUILD", "sh_library(name = 'cycles2', srcs = glob(['*.sh']))");
    cycles1BuildFilePath.getParentDirectory().getRelative("cycles1.sh").createSymbolicLink(new PathFragment("cycles1.sh"));
    cycles2BuildFilePath.getParentDirectory().getRelative("cycles2.sh").createSymbolicLink(new PathFragment("cycles2.sh"));
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    LoadingFailureRecorder recorder = new LoadingFailureRecorder();
    eventBus.register(recorder);
    AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//gp");
    assertThat(result.hasError()).isTrue();
    assertThat(recorder.events).hasSize(2);
    assertTrue(recorder.events.toString(), recorder.events.contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//cycles1"))));
    assertTrue(recorder.events.toString(), recorder.events.contains(Pair.of(Label.parseAbsolute("//gp"), Label.parseAbsolute("//cycles2"))));
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Example 64 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class BuildViewTest method testCircularDependencyWithKeepGoing.

/**
   * Regression test: IllegalStateException in BuildView.update() on circular dependency instead of
   * graceful failure.
   */
@Test
public void testCircularDependencyWithKeepGoing() throws Exception {
    scratch.file("cycle/BUILD", "cc_library(name = 'foo', srcs = ['foo.cc'], deps = [':bar'])", "cc_library(name = 'bar', srcs = ['bar.cc'], deps = [':foo'])", "cc_library(name = 'bat', srcs = ['bat.cc'], deps = [':bas'])", "cc_library(name = 'bas', srcs = ['bas.cc'], deps = [':bau'])", "cc_library(name = 'bau', srcs = ['bas.cc'], deps = [':bas'])", "cc_library(name = 'baz', srcs = ['baz.cc'])");
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    LoadingFailureRecorder loadingFailureRecorder = new LoadingFailureRecorder();
    AnalysisFailureRecorder analysisFailureRecorder = new AnalysisFailureRecorder();
    eventBus.register(loadingFailureRecorder);
    eventBus.register(analysisFailureRecorder);
    update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//cycle:foo", "//cycle:bat", "//cycle:baz");
    assertContainsEvent("in cc_library rule //cycle:foo: cycle in dependency graph:");
    assertContainsEvent("in cc_library rule //cycle:bas: cycle in dependency graph:");
    assertContainsEvent("errors encountered while analyzing target '//cycle:foo': it will not be built");
    assertContainsEvent("errors encountered while analyzing target '//cycle:bat': it will not be built");
    // With interleaved loading and analysis, we can no longer distinguish loading-phase cycles
    // and analysis-phase cycles. This was previously reported as a loading-phase cycle, as it
    // happens with any configuration (cycle is hard-coded in the BUILD files). Also see the
    // test below.
    assertThat(Iterables.transform(analysisFailureRecorder.events, ANALYSIS_EVENT_TO_STRING_PAIR)).containsExactly(Pair.of("//cycle:foo", "//cycle:foo"), Pair.of("//cycle:bat", "//cycle:bas"));
}
Also used : EventBus(com.google.common.eventbus.EventBus) Test(org.junit.Test)

Example 65 with EventBus

use of com.google.common.eventbus.EventBus in project bazel by bazelbuild.

the class BuildViewTest method testConvolutedLoadRootCauseAnalysis.

@Test
public void testConvolutedLoadRootCauseAnalysis() throws Exception {
    // You need license declarations in third_party. We use this constraint to
    // create targets that are loadable, but are in error.
    scratch.file("third_party/first/BUILD", "sh_library(name='first', deps=['//third_party/second'], licenses=['notice'])");
    scratch.file("third_party/second/BUILD", "sh_library(name='second', deps=['//third_party/third'], licenses=['notice'])");
    scratch.file("third_party/third/BUILD", "sh_library(name='third', deps=['//third_party/fourth'], licenses=['notice'])");
    scratch.file("third_party/fourth/BUILD", "sh_library(name='fourth', deps=['//third_party/fifth'])");
    scratch.file("third_party/fifth/BUILD", "sh_library(name='fifth', licenses=['notice'])");
    reporter.removeHandler(failFastHandler);
    EventBus eventBus = new EventBus();
    LoadingFailureRecorder recorder = new LoadingFailureRecorder();
    eventBus.register(recorder);
    // Note: no need to run analysis for a loading failure.
    AnalysisResult result = update(eventBus, defaultFlags().with(Flag.KEEP_GOING), "//third_party/first", "//third_party/third");
    assertThat(result.hasError()).isTrue();
    assertThat(recorder.events).hasSize(2);
    assertTrue(recorder.events.toString(), recorder.events.contains(Pair.of(Label.parseAbsolute("//third_party/first"), Label.parseAbsolute("//third_party/fourth"))));
    assertThat(recorder.events).contains(Pair.of(Label.parseAbsolute("//third_party/third"), Label.parseAbsolute("//third_party/fourth")));
}
Also used : EventBus(com.google.common.eventbus.EventBus) AnalysisResult(com.google.devtools.build.lib.analysis.BuildView.AnalysisResult) Test(org.junit.Test)

Aggregations

EventBus (com.google.common.eventbus.EventBus)85 Test (org.junit.Test)56 BuckEventBus (com.facebook.buck.event.BuckEventBus)21 FakeClock (com.facebook.buck.timing.FakeClock)19 EasyMock.anyObject (org.easymock.EasyMock.anyObject)18 Reporter (com.google.devtools.build.lib.events.Reporter)15 WatchEvent (java.nio.file.WatchEvent)12 Subscribe (com.google.common.eventbus.Subscribe)11 AnalysisResult (com.google.devtools.build.lib.analysis.BuildView.AnalysisResult)8 Before (org.junit.Before)8 Path (com.google.devtools.build.lib.vfs.Path)7 FakeWatchmanClient (com.facebook.buck.io.FakeWatchmanClient)6 ActionExecutionMetadata (com.google.devtools.build.lib.actions.ActionExecutionMetadata)4 ResourceHandle (com.google.devtools.build.lib.actions.ResourceManager.ResourceHandle)4 BuildLangTypedAttributeValuesMap (com.google.devtools.build.lib.packages.RuleFactory.BuildLangTypedAttributeValuesMap)4 HashMap (java.util.HashMap)4 Executor (com.google.devtools.build.lib.actions.Executor)3 Event (com.google.devtools.build.lib.events.Event)3 SuiteHint (com.carrotsearch.ant.tasks.junit4.balancers.SuiteHint)2 AggregatedQuitEvent (com.carrotsearch.ant.tasks.junit4.events.aggregated.AggregatedQuitEvent)2