Skip to content

Commit

Permalink
Fix [Prepa] actions stuck in active state (#14325)
Browse files Browse the repository at this point in the history
Fixed #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 #14020.

PiperOrigin-RevId: 398165993
(cherry picked from commit 639f89d)

Co-authored-by: Brandon Jacklyn <[email protected]>
  • Loading branch information
bjacklyn and Brandon Jacklyn authored Nov 25, 2021
1 parent af74287 commit 748138f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,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 @@ -579,10 +584,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
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,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 @@ -619,6 +620,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 @@ -637,6 +639,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 @@ -655,6 +658,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 748138f

Please sign in to comment.