Skip to content

Commit

Permalink
Fix [Prepa] actions stuck in active state
Browse files Browse the repository at this point in the history
Fixed bazelbuild#13985

UiStateTracker can process ActionProgress events after an ActionCompletion event
has been fired. This has the effect of recreating the action object in the activeActions
Map because Map.computeIfAbsent() is being used to retrieve the action.

Therefore, a new method getActionStateIfPresent is created which will return
the action if it exists, otherwise return null, and actionProgress() uses this
method so as to not inadverntantly recreate actions after they have already
completed and been removed from the Map.

Closes bazelbuild#14020.

PiperOrigin-RevId: 398165993
  • Loading branch information
Brandon Jacklyn authored and Copybara-Service committed Sep 22, 2021
1 parent 003e2d0 commit 639f89d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Expand Up @@ -530,6 +530,11 @@ private ActionState getActionState(
return activeActions.computeIfAbsent(actionId, (key) -> new ActionState(action, nanoTimeNow));
}

@Nullable
private ActionState getActionStateIfPresent(Artifact actionId) {
return activeActions.get(actionId);
}

void actionStarted(ActionStartedEvent event) {
Action action = event.getAction();
Artifact actionId = action.getPrimaryOutput();
Expand Down Expand Up @@ -583,10 +588,12 @@ void runningAction(RunningActionEvent event) {
}

void actionProgress(ActionProgressEvent event) {
ActionExecutionMetadata action = event.action();
Artifact actionId = event.action().getPrimaryOutput();
long now = clock.nanoTime();
getActionState(action, actionId, now).onProgressEvent(event, now);
ActionState actionState = getActionStateIfPresent(actionId);
if (actionState != null) {
actionState.onProgressEvent(event, now);
}
}

void actionCompletion(ActionScanningCompletedEvent event) {
Expand Down
Expand Up @@ -603,6 +603,7 @@ public void actionProgress_visible() throws Exception {
ManualClock clock = new ManualClock();
Action action = createDummyAction("Some random action");
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 70);
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
stateTracker.actionProgress(
ActionProgressEvent.create(action, "action-id", "action progress", false));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
Expand All @@ -621,6 +622,7 @@ public void actionProgress_withTooSmallWidth_progressSkipped() throws Exception
ManualClock clock = new ManualClock();
Action action = createDummyAction("Some random action");
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 30);
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
stateTracker.actionProgress(
ActionProgressEvent.create(action, "action-id", "action progress", false));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
Expand All @@ -639,6 +641,7 @@ public void actionProgress_withSmallWidth_progressShortened() throws Exception {
ManualClock clock = new ManualClock();
Action action = createDummyAction("Some random action");
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 50);
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
stateTracker.actionProgress(
ActionProgressEvent.create(action, "action-id", "action progress", false));
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
Expand All @@ -657,6 +660,7 @@ public void actionProgress_multipleProgress_displayInOrder() throws Exception {
ManualClock clock = new ManualClock();
Action action = createDummyAction("Some random action");
UiStateTracker stateTracker = new UiStateTracker(clock, /* targetWidth= */ 70);
stateTracker.actionStarted(new ActionStartedEvent(action, clock.nanoTime()));
stateTracker.actionProgress(
ActionProgressEvent.create(action, "action-id1", "action progress 1", false));
stateTracker.actionProgress(
Expand Down

0 comments on commit 639f89d

Please sign in to comment.