Search in sources :

Example 1 with DistBuildStatusEvent

use of com.facebook.buck.distributed.DistBuildStatusEvent in project buck by facebook.

the class SuperConsoleEventBusListenerTest method testSimpleDistBuildWithProgress.

@Test
public void testSimpleDistBuildWithProgress() throws IOException {
    Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
    BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
    SuperConsoleEventBusListener listener = createSuperConsole(fakeClock, eventBus);
    BuildTarget fakeTarget = BuildTargetFactory.newInstance("//banana:stand");
    BuildTarget cachedTarget = BuildTargetFactory.newInstance("//chicken:dance");
    ImmutableSet<BuildTarget> buildTargets = ImmutableSet.of(fakeTarget, cachedTarget);
    Iterable<String> buildArgs = Iterables.transform(buildTargets, Object::toString);
    ProgressEstimator e = new ProgressEstimator(getStorageForTest(), eventBus, ObjectMappers.newDefaultInstance());
    listener.setProgressEstimator(e);
    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"));
    // trigger a distributed build instead of a local build
    BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs, true);
    eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    ParseEvent.Started parseStarted = ParseEvent.started(buildTargets);
    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, "[+] DISTBUILD STATUS: INIT...", "[+] BUILDING...0.1s [0%]"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new DistBuildStatusEvent(DistBuildStatus.builder().setStatus(BuildStatus.QUEUED).setMessage("step 1").setETAMillis(2000).setLogBook(Optional.empty()).build()), 800L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 900L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] DISTBUILD STATUS: QUEUED... ETA: 2.0s (step 1)", "[+] BUILDING...0.5s [29%]"));
    LinkedList<LogRecord> debugLogs = new LinkedList<LogRecord>();
    LogRecord log = new LogRecord();
    log.setName("buck-client");
    log.setTimestampMillis(0);
    debugLogs.add(log);
    final String distDebugLine = "Distributed build debug info:";
    final String logLine1 = "[1970-01-01 00:00:00.000] buck-client";
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new DistBuildStatusEvent(DistBuildStatus.builder().setStatus(BuildStatus.BUILDING).setMessage("step 2").setETAMillis(1800).setLogBook(debugLogs).build()), 1000L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 1100L, ImmutableList.of(distDebugLine, logLine1, parsingLine, DOWNLOAD_STRING, "[+] DISTBUILD STATUS: BUILDING... ETA: 1.8s (step 2)", "[+] BUILDING...0.7s [50%]"));
    log = new LogRecord();
    log.setName("buck-frontend");
    log.setTimestampMillis(100);
    debugLogs.add(log);
    final String logLine2 = "[1970-01-01 00:00:00.100] buck-frontend";
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new DistBuildStatusEvent(DistBuildStatus.builder().setStatus(BuildStatus.BUILDING).setMessage("step 2").setETAMillis(1600).setLogBook(debugLogs).build()), 1200L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsole(listener, 1300L, ImmutableList.of(distDebugLine, logLine1, logLine2, parsingLine, DOWNLOAD_STRING, "[+] DISTBUILD STATUS: BUILDING... ETA: 1.6s (step 2)", "[+] BUILDING...0.9s [64%]"));
    log = new LogRecord();
    log.setName("build_slave_start");
    log.setTimestampMillis(200);
    debugLogs.add(log);
    final String logLine3 = "[1970-01-01 00:00:00.200] build_slave_start";
    log = new LogRecord();
    log.setName("build_slave_end");
    log.setTimestampMillis(300);
    debugLogs.add(log);
    final String logLine4 = "[1970-01-01 00:00:00.300] build_slave_end";
    eventBus.postWithoutConfiguring(configureTestEventAtTime(new DistBuildStatusEvent(DistBuildStatus.builder().setStatus(BuildStatus.FINISHED_SUCCESSFULLY).setMessage("step 3").setETAMillis(0).setLogBook(debugLogs).build()), 1400L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String distbuildLine = "[-] DISTBUILD STATUS: FINISHED_SUCCESSFULLY... (step 3)";
    validateConsole(listener, 1500L, ImmutableList.of(distDebugLine, logLine1, logLine2, logLine3, logLine4, parsingLine, DOWNLOAD_STRING, distbuildLine, "[+] BUILDING...1.1s [100%]"));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildEvent.finished(buildEventStarted, 0), 1600L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    final String buildingLine = "[-] BUILDING...FINISHED 1.2s [100%]";
    validateConsole(listener, 1600L, ImmutableList.of(distDebugLine, logLine1, logLine2, logLine3, logLine4, parsingLine, FINISHED_DOWNLOAD_STRING, distbuildLine, buildingLine));
    eventBus.postWithoutConfiguring(configureTestEventAtTime(ConsoleEvent.severe(SEVERE_MESSAGE), 1700L, TimeUnit.MILLISECONDS, /* threadId */
    0L));
    validateConsoleWithLogLines(listener, 1750L, ImmutableList.of(distDebugLine, logLine1, logLine2, logLine3, logLine4, parsingLine, FINISHED_DOWNLOAD_STRING, distbuildLine, buildingLine), ImmutableList.of(SEVERE_MESSAGE));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ConsoleTestUtils.postStoreFinished(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished) ConsoleTestUtils.postStoreStarted(com.facebook.buck.event.listener.ConsoleTestUtils.postStoreStarted) DistBuildStatusEvent(com.facebook.buck.distributed.DistBuildStatusEvent) ProjectBuildFileParseEvents(com.facebook.buck.json.ProjectBuildFileParseEvents) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Clock(com.facebook.buck.timing.Clock) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) LinkedList(java.util.LinkedList) LogRecord(com.facebook.buck.distributed.thrift.LogRecord) BuildTarget(com.facebook.buck.model.BuildTarget) BuildEvent(com.facebook.buck.rules.BuildEvent) ParseEvent(com.facebook.buck.parser.ParseEvent) Test(org.junit.Test)

Aggregations

DistBuildStatusEvent (com.facebook.buck.distributed.DistBuildStatusEvent)1 LogRecord (com.facebook.buck.distributed.thrift.LogRecord)1 ActionGraphEvent (com.facebook.buck.event.ActionGraphEvent)1 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 ConsoleTestUtils.postStoreFinished (com.facebook.buck.event.listener.ConsoleTestUtils.postStoreFinished)1 ConsoleTestUtils.postStoreStarted (com.facebook.buck.event.listener.ConsoleTestUtils.postStoreStarted)1 ProjectBuildFileParseEvents (com.facebook.buck.json.ProjectBuildFileParseEvents)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 ParseEvent (com.facebook.buck.parser.ParseEvent)1 BuildEvent (com.facebook.buck.rules.BuildEvent)1 Clock (com.facebook.buck.timing.Clock)1 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1