use of com.facebook.buck.rules.keys.FakeRuleKeyFactory in project buck by facebook.
the class SuperConsoleEventBusListenerTest method testBuildRuleSuspendResumeEvents.
@Test
public void testBuildRuleSuspendResumeEvents() {
Clock fakeClock = new IncrementingFakeClock(TimeUnit.SECONDS.toNanos(1));
BuckEventBus eventBus = BuckEventBusFactory.newInstance(fakeClock);
SuperConsoleEventBusListener listener = createSuperConsole(fakeClock, eventBus);
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
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, pathResolver, ImmutableSortedSet.of());
String stepShortName = "doing_something";
String stepDescription = "working hard";
UUID stepUuid = UUID.randomUUID();
FakeRuleKeyFactory ruleKeyFactory = new FakeRuleKeyFactory(ImmutableMap.of(fakeTarget, new RuleKey("aaaa")));
// Start the build.
BuildEvent.Started buildEventStarted = BuildEvent.started(buildArgs);
eventBus.postWithoutConfiguring(configureTestEventAtTime(buildEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Start and stop parsing.
String parsingLine = "[-] PROCESSING BUCK FILES...FINISHED 0.0s";
ParseEvent.Started parseStarted = ParseEvent.started(buildTargets);
eventBus.postWithoutConfiguring(configureTestEventAtTime(parseStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(ParseEvent.finished(parseStarted, Optional.empty()), 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(ActionGraphEvent.finished(ActionGraphEvent.started()), 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Start the rule.
BuildRuleEvent.Started started = BuildRuleEvent.started(fakeRule, durationTracker);
eventBus.postWithoutConfiguring(configureTestEventAtTime(started, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Post events that run a step for 100ms.
StepEvent.Started stepEventStarted = StepEvent.started(stepShortName, stepDescription, stepUuid);
eventBus.postWithoutConfiguring(configureTestEventAtTime(stepEventStarted, 0L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(stepEventStarted, /* exitCode */
0), 100L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Suspend the rule.
BuildRuleEvent.Suspended suspended = BuildRuleEvent.suspended(started, ruleKeyFactory);
eventBus.postWithoutConfiguring(configureTestEventAtTime(suspended, 100L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify that the rule isn't printed now that it's suspended.
validateConsole(listener, 200L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.2s", " |=> IDLE"));
// Resume the rule.
BuildRuleEvent.Resumed resumed = BuildRuleEvent.resumed(fakeRule, durationTracker, ruleKeyFactory);
eventBus.postWithoutConfiguring(configureTestEventAtTime(resumed, 300L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify that we print "checking local..." now that we've resumed, and that we're accounting
// for previous running time.
validateConsole(listener, 300L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.3s", " |=> //banana:stand... 0.1s (checking_cache)"));
// Post events that run another step.
StepEvent.Started step2EventStarted = StepEvent.started(stepShortName, stepDescription, stepUuid);
eventBus.postWithoutConfiguring(configureTestEventAtTime(step2EventStarted, 400L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify the current console now accounts for the step.
validateConsole(listener, 500L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.5s", " |=> //banana:stand... 0.3s (running doing_something[0.1s])"));
// Finish the step and rule.
eventBus.postWithoutConfiguring(configureTestEventAtTime(StepEvent.finished(step2EventStarted, /* exitCode */
0), 600L, TimeUnit.MILLISECONDS, /* threadId */
0L));
eventBus.postWithoutConfiguring(configureTestEventAtTime(BuildRuleEvent.finished(resumed, BuildRuleKeys.of(new RuleKey("aaaa")), BuildRuleStatus.SUCCESS, CacheResult.miss(), Optional.of(BuildRuleSuccessType.BUILT_LOCALLY), Optional.empty(), Optional.empty()), 600L, TimeUnit.MILLISECONDS, /* threadId */
0L));
// Verify that the rule isn't printed now that it's finally finished..
validateConsole(listener, 700L, ImmutableList.of(parsingLine, DOWNLOAD_STRING, "[+] BUILDING...0.7s", " |=> IDLE"));
}
use of com.facebook.buck.rules.keys.FakeRuleKeyFactory in project buck by facebook.
the class BuildThreadStateRendererTest method createRuleBeginningEventOptional.
private static Optional<? extends BuildRuleEvent.BeginningBuildRuleEvent> createRuleBeginningEventOptional(long threadId, long timeMs, long durationMs, BuildRule rule) {
BuildRuleDurationTracker durationTracker = new BuildRuleDurationTracker();
durationTracker.setDuration(rule, new ClockDuration(durationMs, 0, 0));
RuleKey ruleKey = new RuleKey(HashCode.fromString("aa"));
return Optional.of(TestEventConfigurator.configureTestEventAtTime(BuildRuleEvent.resumed(rule, durationTracker, new FakeRuleKeyFactory(ImmutableMap.of(rule.getBuildTarget(), ruleKey))), timeMs, TimeUnit.MILLISECONDS, threadId));
}
Aggregations