Search in sources :

Example 1 with IncrementingFakeClock

use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.

the class HttpArtifactCacheTest method errorTextReplaced.

@Test
public void errorTextReplaced() throws InterruptedException {
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    final String cacheName = "http cache";
    final RuleKey ruleKey = new RuleKey("00000000000000000000000000000000");
    final RuleKey otherRuleKey = new RuleKey("11111111111111111111111111111111");
    final String data = "data";
    final AtomicBoolean consoleEventReceived = new AtomicBoolean(false);
    argsBuilder.setCacheName(cacheName).setProjectFilesystem(filesystem).setBuckEventBus(new BuckEventBus(new IncrementingFakeClock(), new BuildId()) {

        @Override
        public void post(BuckEvent event) {
            if (event instanceof ConsoleEvent) {
                consoleEventReceived.set(true);
                ConsoleEvent consoleEvent = (ConsoleEvent) event;
                assertThat(consoleEvent.getMessage(), Matchers.containsString(cacheName));
                assertThat(consoleEvent.getMessage(), Matchers.containsString("incorrect key name"));
            }
        }
    }).setFetchClient(withMakeRequest((path, requestBuilder) -> {
        Request request = requestBuilder.url(SERVER + path).build();
        Response response = new Response.Builder().request(request).protocol(Protocol.HTTP_1_1).code(HttpURLConnection.HTTP_OK).body(createResponseBody(ImmutableSet.of(otherRuleKey), ImmutableMap.of(), ByteSource.wrap(data.getBytes(Charsets.UTF_8)), data)).build();
        return new OkHttpResponseWrapper(response);
    }));
    HttpArtifactCache cache = new HttpArtifactCache(argsBuilder.build());
    Path output = Paths.get("output/file");
    CacheResult result = cache.fetch(ruleKey, LazyPath.ofInstance(output));
    assertEquals(CacheResultType.ERROR, result.getType());
    assertEquals(Optional.empty(), filesystem.readFileIfItExists(output));
    assertTrue(consoleEventReceived.get());
    cache.close();
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuckEventBus(com.facebook.buck.event.BuckEventBus) HttpURLConnection(java.net.HttpURLConnection) DataInputStream(java.io.DataInputStream) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BuckEvent(com.facebook.buck.event.BuckEvent) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Assert.assertThat(org.junit.Assert.assertThat) Lists(com.google.common.collect.Lists) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) BuildId(com.facebook.buck.model.BuildId) RuleKey(com.facebook.buck.rules.RuleKey) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Response(okhttp3.Response) ByteSource(com.google.common.io.ByteSource) HttpResponse(com.facebook.buck.slb.HttpResponse) Path(java.nio.file.Path) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) HttpService(com.facebook.buck.slb.HttpService) Before(org.junit.Before) Charsets(com.google.common.base.Charsets) Request(okhttp3.Request) Buffer(okio.Buffer) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Assert.assertTrue(org.junit.Assert.assertTrue) OkHttpResponseWrapper(com.facebook.buck.slb.OkHttpResponseWrapper) Matchers(org.hamcrest.Matchers) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Sets(com.google.common.collect.Sets) List(java.util.List) Paths(java.nio.file.Paths) LazyPath(com.facebook.buck.io.LazyPath) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Optional(java.util.Optional) Protocol(okhttp3.Protocol) Assert.assertEquals(org.junit.Assert.assertEquals) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Path(java.nio.file.Path) LazyPath(com.facebook.buck.io.LazyPath) RuleKey(com.facebook.buck.rules.RuleKey) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Request(okhttp3.Request) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) OkHttpResponseWrapper(com.facebook.buck.slb.OkHttpResponseWrapper) BuckEvent(com.facebook.buck.event.BuckEvent) Response(okhttp3.Response) HttpResponse(com.facebook.buck.slb.HttpResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BuildId(com.facebook.buck.model.BuildId) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) Test(org.junit.Test)

Example 2 with IncrementingFakeClock

use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.

the class ChromeTraceBuildListenerTest method testBuildJson.

@Test
public void testBuildJson() throws IOException {
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
    ObjectMapper mapper = ObjectMappers.newDefaultInstance();
    BuildId buildId = new BuildId("ChromeTraceBuildListenerTestBuildId");
    ChromeTraceBuildListener listener = new ChromeTraceBuildListener(projectFilesystem, invocationInfo, new FakeClock(TIMESTAMP_NANOS), mapper, Locale.US, TimeZone.getTimeZone("America/Los_Angeles"), /* tracesToKeep */
    42, false);
    BuildTarget target = BuildTargetFactory.newInstance("//fake:rule");
    FakeBuildRule rule = new FakeBuildRule(target, new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of());
    RuleKey ruleKey = new RuleKey("abc123");
    String stepShortName = "fakeStep";
    String stepDescription = "I'm a Fake Step!";
    UUID stepUuid = UUID.randomUUID();
    ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(target);
    Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
    Clock fakeClock = new IncrementingFakeClock(TimeUnit.MILLISECONDS.toNanos(1));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock, buildId);
    eventBus.register(listener);
    CommandEvent.Started commandEventStarted = CommandEvent.started("party", ImmutableList.of("arg1", "arg2"), true, 23L);
    eventBus.post(commandEventStarted);
    eventBus.post(new PerfStatsTracking.MemoryPerfStatsEvent(/* freeMemoryBytes */
    1024 * 1024L, /* totalMemoryBytes */
    3 * 1024 * 1024L, /* timeSpentInGcMs */
    -1, /* currentMemoryBytesUsageByPool */
    ImmutableMap.of("flower", 42L * 1024 * 1024)));
    ArtifactCacheConnectEvent.Started artifactCacheConnectEventStarted = ArtifactCacheConnectEvent.started();
    eventBus.post(artifactCacheConnectEventStarted);
    eventBus.post(ArtifactCacheConnectEvent.finished(artifactCacheConnectEventStarted));
    BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
    eventBus.post(buildEventStarted);
    HttpArtifactCacheEvent.Started artifactCacheEventStarted = HttpArtifactCacheEvent.newFetchStartedEvent(ruleKey);
    eventBus.post(artifactCacheEventStarted);
    eventBus.post(HttpArtifactCacheEvent.newFinishedEventBuilder(artifactCacheEventStarted).setFetchDataBuilder(HttpArtifactCacheEventFetchData.builder().setFetchResult(CacheResult.hit("http"))).build());
    ArtifactCompressionEvent.Started artifactCompressionStartedEvent = ArtifactCompressionEvent.started(ArtifactCompressionEvent.Operation.COMPRESS, ImmutableSet.of(ruleKey));
    eventBus.post(artifactCompressionStartedEvent);
    eventBus.post(ArtifactCompressionEvent.finished(artifactCompressionStartedEvent));
    BuildRuleEvent.Started started = BuildRuleEvent.started(rule, durationTracker);
    eventBus.post(started);
    eventBus.post(StepEvent.started(stepShortName, stepDescription, stepUuid));
    JavacPhaseEvent.Started runProcessorsStartedEvent = JavacPhaseEvent.started(target, JavacPhaseEvent.Phase.RUN_ANNOTATION_PROCESSORS, ImmutableMap.of());
    eventBus.post(runProcessorsStartedEvent);
    String annotationProcessorName = "com.facebook.FakeProcessor";
    AnnotationProcessingEvent.Operation operation = AnnotationProcessingEvent.Operation.PROCESS;
    int annotationRound = 1;
    boolean isLastRound = false;
    AnnotationProcessingEvent.Started annotationProcessingEventStarted = AnnotationProcessingEvent.started(target, annotationProcessorName, operation, annotationRound, isLastRound);
    eventBus.post(annotationProcessingEventStarted);
    HttpArtifactCacheEvent.Scheduled httpScheduled = HttpArtifactCacheEvent.newStoreScheduledEvent(Optional.of("TARGET_ONE"), ImmutableSet.of(ruleKey));
    HttpArtifactCacheEvent.Started httpStarted = HttpArtifactCacheEvent.newStoreStartedEvent(httpScheduled);
    eventBus.post(httpStarted);
    HttpArtifactCacheEvent.Finished httpFinished = HttpArtifactCacheEvent.newFinishedEventBuilder(httpStarted).build();
    eventBus.post(httpFinished);
    final CompilerPluginDurationEvent.Started processingPartOneStarted = CompilerPluginDurationEvent.started(target, annotationProcessorName, "processingPartOne", ImmutableMap.of());
    eventBus.post(processingPartOneStarted);
    eventBus.post(CompilerPluginDurationEvent.finished(processingPartOneStarted, ImmutableMap.of()));
    eventBus.post(AnnotationProcessingEvent.finished(annotationProcessingEventStarted));
    eventBus.post(JavacPhaseEvent.finished(runProcessorsStartedEvent, ImmutableMap.of()));
    eventBus.post(StepEvent.finished(StepEvent.started(stepShortName, stepDescription, stepUuid), 0));
    eventBus.post(BuildRuleEvent.finished(started, BuildRuleKeys.of(ruleKey), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()));
    try (final SimplePerfEvent.Scope scope1 = SimplePerfEvent.scope(eventBus, PerfEventId.of("planning"), ImmutableMap.<String, Object>of("nefarious", "true"))) {
        try (final SimplePerfEvent.Scope scope2 = SimplePerfEvent.scope(eventBus, PerfEventId.of("scheming"))) {
            scope2.appendFinishedInfo("success", "false");
        }
    }
    eventBus.post(BuildEvent.finished(buildEventStarted, 0));
    eventBus.post(CommandEvent.finished(commandEventStarted, /* exitCode */
    0));
    listener.outputTrace(new BuildId("BUILD_ID"));
    File resultFile = new File(tmpDir.getRoot(), "buck-out/log/build.trace");
    List<ChromeTraceEvent> originalResultList = mapper.readValue(resultFile, new TypeReference<List<ChromeTraceEvent>>() {
    });
    List<ChromeTraceEvent> resultListCopy = new ArrayList<>();
    resultListCopy.addAll(originalResultList);
    ImmutableMap<String, String> emptyArgs = ImmutableMap.of();
    assertNextResult(resultListCopy, "process_name", ChromeTraceEvent.Phase.METADATA, ImmutableMap.of("name", "buck"));
    assertNextResult(resultListCopy, "party", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("command_args", "arg1 arg2"));
    assertNextResult(resultListCopy, "memory", ChromeTraceEvent.Phase.COUNTER, ImmutableMap.of("used_memory_mb", "2", "free_memory_mb", "1", "total_memory_mb", "3", "time_spent_in_gc_sec", "0", "pool_flower_mb", "42"));
    assertNextResult(resultListCopy, "artifact_connect", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
    assertNextResult(resultListCopy, "artifact_connect", ChromeTraceEvent.Phase.END, emptyArgs);
    assertNextResult(resultListCopy, "build", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
    assertNextResult(resultListCopy, "http_artifact_fetch", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("rule_key", "abc123"));
    assertNextResult(resultListCopy, "http_artifact_fetch", ChromeTraceEvent.Phase.END, ImmutableMap.of("rule_key", "abc123", "success", "true", "cache_result", "HTTP_HIT"));
    assertNextResult(resultListCopy, "artifact_compress", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("rule_key", "abc123"));
    assertNextResult(resultListCopy, "artifact_compress", ChromeTraceEvent.Phase.END, ImmutableMap.of("rule_key", "abc123"));
    // BuildRuleEvent.Started
    assertNextResult(resultListCopy, "//fake:rule", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of());
    assertNextResult(resultListCopy, "fakeStep", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
    assertNextResult(resultListCopy, "run annotation processors", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
    assertNextResult(resultListCopy, "com.facebook.FakeProcessor.process", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
    assertNextResult(resultListCopy, "http_artifact_store", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("rule_key", "abc123"));
    assertNextResult(resultListCopy, "http_artifact_store", ChromeTraceEvent.Phase.END, ImmutableMap.of("success", "true", "rule_key", "abc123"));
    assertNextResult(resultListCopy, "processingPartOne", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
    assertNextResult(resultListCopy, "processingPartOne", ChromeTraceEvent.Phase.END, emptyArgs);
    assertNextResult(resultListCopy, "com.facebook.FakeProcessor.process", ChromeTraceEvent.Phase.END, emptyArgs);
    assertNextResult(resultListCopy, "run annotation processors", ChromeTraceEvent.Phase.END, emptyArgs);
    assertNextResult(resultListCopy, "fakeStep", ChromeTraceEvent.Phase.END, ImmutableMap.of("description", "I'm a Fake Step!", "exit_code", "0"));
    assertNextResult(resultListCopy, "//fake:rule", ChromeTraceEvent.Phase.END, ImmutableMap.of("cache_result", "miss", "success_type", "BUILT_LOCALLY"));
    assertNextResult(resultListCopy, "planning", ChromeTraceEvent.Phase.BEGIN, ImmutableMap.of("nefarious", "true"));
    assertNextResult(resultListCopy, "scheming", ChromeTraceEvent.Phase.BEGIN, emptyArgs);
    assertNextResult(resultListCopy, "scheming", ChromeTraceEvent.Phase.END, ImmutableMap.of("success", "false"));
    assertNextResult(resultListCopy, "planning", ChromeTraceEvent.Phase.END, emptyArgs);
    assertNextResult(resultListCopy, "build", ChromeTraceEvent.Phase.END, emptyArgs);
    assertNextResult(resultListCopy, "party", ChromeTraceEvent.Phase.END, ImmutableMap.of("command_args", "arg1 arg2", "daemon", "true"));
    assertEquals(0, resultListCopy.size());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ChromeTraceEvent(com.facebook.buck.event.ChromeTraceEvent) ArrayList(java.util.ArrayList) Clock(com.facebook.buck.timing.Clock) FakeClock(com.facebook.buck.timing.FakeClock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) UUID(java.util.UUID) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) PerfStatsTracking(com.facebook.buck.util.perf.PerfStatsTracking) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RuleKey(com.facebook.buck.rules.RuleKey) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) ArtifactCompressionEvent(com.facebook.buck.event.ArtifactCompressionEvent) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildEvent(com.facebook.buck.rules.BuildEvent) BuildRuleEvent(com.facebook.buck.rules.BuildRuleEvent) File(java.io.File) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) JavacPhaseEvent(com.facebook.buck.jvm.java.tracing.JavacPhaseEvent) CommandEvent(com.facebook.buck.event.CommandEvent) AnnotationProcessingEvent(com.facebook.buck.jvm.java.AnnotationProcessingEvent) FakeClock(com.facebook.buck.timing.FakeClock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) CompilerPluginDurationEvent(com.facebook.buck.event.CompilerPluginDurationEvent) BuildId(com.facebook.buck.model.BuildId) HttpArtifactCacheEvent(com.facebook.buck.artifact_cache.HttpArtifactCacheEvent) ArtifactCacheConnectEvent(com.facebook.buck.artifact_cache.ArtifactCacheConnectEvent) Test(org.junit.Test)

Example 3 with IncrementingFakeClock

use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.

the class BroadcastEventListenerTest method tryBroadcastInMultipleBuses.

@Test
public void tryBroadcastInMultipleBuses() {
    BuckEventBus bus1 = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)), new BuildId("bus1"));
    BuckEventBus bus2 = BuckEventBusFactory.newInstance(new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1)), new BuildId("bus2"));
    bus1.register(new Object() {

        @Subscribe
        public void actionGraphCacheMiss(ActionGraphEvent.Cache.Miss event) {
            trackedEvents.add(event);
        }
    });
    bus2.register(new Object() {

        @Subscribe
        public void actionGraphCacheHit(ActionGraphEvent.Cache.Hit event) {
            trackedEvents.add(event);
        }

        @Subscribe
        public void actionGraphCacheMiss(ActionGraphEvent.Cache.Miss event) {
            trackedEvents.add(event);
        }
    });
    BroadcastEventListener listener = new BroadcastEventListener();
    listener.addEventBus(bus1);
    listener.addEventBus(bus2);
    listener.broadcast(ActionGraphEvent.Cache.hit());
    listener.broadcast(ActionGraphEvent.Cache.miss(/* cacheWasEmpty */
    false));
    assertEquals(countEventsOf(ActionGraphEvent.Cache.Miss.class), 2);
    assertEquals(countEventsOf(ActionGraphEvent.Cache.Hit.class), 1);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Subscribe(com.google.common.eventbus.Subscribe) Test(org.junit.Test)

Example 4 with IncrementingFakeClock

use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.

the class SimpleConsoleEventBusListenerTest method testSimpleBuild.

@Test
public void testSimpleBuild() {
    String expectedOutput = "";
    Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
    TestConsole console = new TestConsole();
    BuildTarget fakeTarget = BuildTargetFactory.newInstance("//banana:stand");
    ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(fakeTarget);
    Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
    FakeBuildRule fakeRule = new FakeBuildRule(fakeTarget, new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of());
    SimpleConsoleEventBusListener listener = new SimpleConsoleEventBusListener(console, fakeClock, TestResultSummaryVerbosity.of(false, false), Locale.US, logPath, new DefaultExecutionEnvironment(ImmutableMap.copyOf(System.getenv()), System.getProperties()));
    eventBus.register(listener);
    final long threadId = 0;
    BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 0L, TimeUnit.MILLISECONDS, threadId));
    ParseEvent.Started parseStarted = ParseEvent.started(buildTargets);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 0L, TimeUnit.MILLISECONDS, threadId));
    assertOutput("", console);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 400L, TimeUnit.MILLISECONDS, threadId));
    expectedOutput += "[-] PARSING BUCK FILES...FINISHED 0.4s\n";
    assertOutput(expectedOutput, console);
    BuildRuleEvent.Started started = BuildRuleEvent.started(fakeRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 600L, TimeUnit.MILLISECONDS, threadId));
    HttpArtifactCacheEvent.Scheduled storeScheduledOne = postStoreScheduled(eventBus, threadId, TARGET_ONE, 700L);
    HttpArtifactCacheEvent.Scheduled storeScheduledTwo = postStoreScheduled(eventBus, threadId, TARGET_TWO, 700L);
    HttpArtifactCacheEvent.Started storeStartedOne = postStoreStarted(eventBus, threadId, 710L, storeScheduledOne);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1000L, TimeUnit.MILLISECONDS, threadId));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1234L, TimeUnit.MILLISECONDS, threadId));
    expectedOutput += "BUILT  0.4s //banana:stand\n" + "[-] BUILDING...FINISHED 0.8s\n" + "WAITING FOR HTTP CACHE UPLOADS 0.00 B (0 COMPLETE/0 FAILED/1 UPLOADING/1 PENDING)\n";
    assertOutput(expectedOutput, console);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ConsoleEvent.severe(SEVERE_MESSAGE), 1500L, TimeUnit.MILLISECONDS, threadId));
    expectedOutput += SEVERE_MESSAGE + "\n";
    assertOutput(expectedOutput, console);
    InstallEvent.Started installEventStarted = configureTestEventAtTime(InstallEvent.started(fakeTarget), 2500L, TimeUnit.MILLISECONDS, threadId);
    eventBus.postWithoutConfiguring(installEventStarted);
    assertOutput(expectedOutput, console);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(InstallEvent.finished(installEventStarted, true, Optional.empty(), Optional.empty()), 4000L, TimeUnit.MILLISECONDS, threadId));
    expectedOutput += "[-] INSTALLING...FINISHED 1.5s\n";
    assertOutput(expectedOutput, console);
    long artifactSizeOne = SizeUnit.MEGABYTES.toBytes(1.5);
    postStoreFinished(eventBus, threadId, artifactSizeOne, 5015L, true, storeStartedOne);
    HttpArtifactCacheEvent.Started storeStartedTwo = postStoreStarted(eventBus, threadId, 5020L, storeScheduledTwo);
    long artifactSizeTwo = 600;
    postStoreFinished(eventBus, threadId, artifactSizeTwo, 5020L, false, storeStartedTwo);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(HttpArtifactCacheEvent.newShutdownEvent(), 6000L, TimeUnit.MILLISECONDS, threadId));
    expectedOutput += "[-] HTTP CACHE UPLOAD...FINISHED 1.50 MB (1 COMPLETE/1 FAILED/0 UPLOADING/0 PENDING)\n";
    assertOutput(expectedOutput, console);
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) RuleKey(com.facebook.buck.rules.RuleKey) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) InstallEvent(com.facebook.buck.event.InstallEvent) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) BuildRuleEvent(com.facebook.buck.rules.BuildRuleEvent) HttpArtifactCacheEvent(com.facebook.buck.artifact_cache.HttpArtifactCacheEvent) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 5 with IncrementingFakeClock

use of com.facebook.buck.timing.IncrementingFakeClock in project buck by facebook.

the class SuperConsoleEventBusListenerTest method testFailingTest.

@Test
public void testFailingTest() {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
    TestConsole console = new TestConsole();
    BuildTarget testTarget = BuildTargetFactory.newInstance("//:test");
    ImmutableSet<BuildTarget> testTargets = ImmutableSet.of(testTarget);
    Iterable<String> testArgs = Iterables.transform(testTargets, Object::toString);
    FakeBuildRule testBuildRule = new FakeBuildRule(testTarget, pathResolver, ImmutableSortedSet.of());
    SuperConsoleEventBusListener listener = new SuperConsoleEventBusListener(emptySuperConsoleConfig, console, fakeClock, noisySummaryVerbosity, new DefaultExecutionEnvironment(ImmutableMap.copyOf(System.getenv()), System.getProperties()), Optional.empty(), Locale.US, logPath, timeZone);
    eventBus.register(listener);
    ProjectBuildFileParseEvents.Started parseEventStarted = new ProjectBuildFileParseEvents.Started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 0L, ImmutableList.of("[+] PARSING BUCK FILES...0.0s"));
    validateConsole(listener, 100L, ImmutableList.of("[+] PARSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new ProjectBuildFileParseEvents.Finished(parseEventStarted), 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 200L, ImmutableList.of("[-] PARSING BUCK FILES...FINISHED 0.2s"));
    BuildEvent.Started buildEventStarted = BuildEvent.started(testArgs);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ParseEvent.Started parseStarted = ParseEvent.started(testTargets);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 300L, ImmutableList.of("[+] PROCESSING BUCK FILES...0.1s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ActionGraphEvent.Started actionGraphStarted = ActionGraphEvent.started();
    eventBus.postWithoutConfiguring(configureTestEventAtTime(actionGraphStarted, 300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(actionGraphStarted), 400L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.2s";
    validateConsole(listener, 540L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.1s"));
    BuildRuleEvent.Started started = BuildRuleEvent.started(testBuildRule, durationTracker);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 600L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 800L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.4s", " |=> //:test...  0.2s (checking_cache)"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(started, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 1000L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1234L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String buildingLine = "[-] BUILDING...FINISHED 0.8s";
    validateConsole(listener, 1300L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.started(// isRunAllTests
    true, TestSelectorList.empty(), // shouldExplainTestSelectorList
    false, ImmutableSet.copyOf(testArgs)), 2500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.5s"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRuleEvent.started(testTarget), 3100L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.7s", " |=> //:test...  0.1s"));
    UUID stepUuid = new UUID(0, 1);
    StepEvent.Started stepEventStarted = StepEvent.started("step_name", "step_desc", stepUuid);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 3300L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3400L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...0.9s", " |=> //:test...  0.3s (running step_name[0.1s])"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, 0), 3500L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3600L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.1s", " |=> //:test...  0.5s"));
    UUID testUUID = new UUID(2, 3);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.started(testUUID, "TestClass", "Foo"), 3700L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 3800L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.3s", " |=> //:test...  0.7s (running Foo[0.1s])"));
    TestResultSummary testResultSummary = new TestResultSummary("TestClass", "Foo", ResultType.FAILURE, // time
    0L, // message
    "Foo.java:47: Assertion failure: 'foo' != 'bar'", // stacktrace
    null, // stdOut
    "Message on stdout", // stdErr
    "Message on stderr");
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestSummaryEvent.finished(testUUID, testResultSummary), 3900L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsoleWithLogLines(listener, 4000L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, "[+] TESTING...1.5s (0 PASS/1 FAIL)", " |=> //:test...  0.9s"), ImmutableList.of("FAILURE TestClass Foo: Foo.java:47: Assertion failure: 'foo' != 'bar'"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(TestRunEvent.finished(ImmutableSet.copyOf(testArgs), ImmutableList.of(TestResults.of(testTarget, ImmutableList.of(new TestCaseSummary("TestClass", ImmutableList.of(testResultSummary))), // contacts
    ImmutableSet.of(), // labels
    ImmutableSet.of()))), 4100L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String testingLine = "[-] TESTING...FINISHED 1.6s (0 PASS/1 FAIL)";
    validateConsoleWithStdOutAndErr(listener, 4200L, ImmutableList.of(parsingLine, FINISHED_DOWNLOAD_STRING, buildingLine, testingLine), ImmutableList.of(), Optional.of(Joiner.on('\n').join("RESULTS FOR ALL TESTS", "FAIL    <100ms  0 Passed   0 Skipped   1 Failed   TestClass", "FAILURE TestClass Foo: Foo.java:47: Assertion failure: 'foo' != 'bar'", "====STANDARD OUT====", "Message on stdout", "====STANDARD ERR====", "Message on stderr", "TESTS FAILED: 1 FAILURE", "Failed target: //:test", "FAIL TestClass", "")), // We don't care about stderr, since the last frame will be flushed there.
    Optional.empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ConsoleTestUtils.postStoreStarted(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreStarted) ProjectBuildFileParseEvents(com.facebook.buck.json.ProjectBuildFileParseEvents) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) UUID(java.util.UUID) ConsoleTestUtils.postStoreFinished(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished) StepEvent(com.facebook.buck.step.StepEvent) RuleKey(com.facebook.buck.rules.RuleKey) DefaultExecutionEnvironment(com.facebook.buck.util.environment.DefaultExecutionEnvironment) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) BuildRuleEvent(com.facebook.buck.rules.BuildRuleEvent) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)30 Test (org.junit.Test)29 BuckEventBus (com.facebook.buck.event.BuckEventBus)25 Clock (com.facebook.buck.timing.Clock)20 BuildTarget (com.facebook.buck.model.BuildTarget)15 BuildEvent (com.facebook.buck.rules.BuildEvent)11 ActionGraphEvent (com.facebook.buck.event.ActionGraphEvent)10 ParseEvent (com.facebook.buck.parser.ParseEvent)10 ConsoleTestUtils.postStoreFinished (com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished)9 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)9 RuleKey (com.facebook.buck.rules.RuleKey)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)9 BuildRuleEvent (com.facebook.buck.rules.BuildRuleEvent)8 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)8 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)8 BuildId (com.facebook.buck.model.BuildId)7 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)7 UUID (java.util.UUID)7 StepEvent (com.facebook.buck.step.StepEvent)6