Skip to content

Commit c8f912e

Browse files
committed
Always prioritize running actions over scheduled actions in UI
Previously it was possible, especially in the short UI, that the oldest action bazel chose to display was scheduled, even though there were newer actions that were running. Now running actions are always prioritized even if they're newer. Fixes #25235
1 parent 9a5d954 commit c8f912e

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

src/main/java/com/google/devtools/build/lib/runtime/UiStateTracker.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -913,16 +913,27 @@ protected String describeAction(
913913
return prefix + message + postfix;
914914
}
915915

916-
protected ActionState getOldestAction() {
917-
long minStart = Long.MAX_VALUE;
918-
ActionState result = null;
916+
private ActionState getOldestAction() {
917+
long minRunningStart = Long.MAX_VALUE;
918+
ActionState oldestRunning = null;
919+
long minScheduledStart = Long.MAX_VALUE;
920+
ActionState oldestScheduled = null;
921+
919922
for (ActionState action : activeActions.values()) {
920-
if (action.nanoStartTime < minStart) {
921-
minStart = action.nanoStartTime;
922-
result = action;
923+
if (action.getPhase().equals(ActionPhase.RUNNING)) {
924+
if (action.nanoStartTime < minRunningStart) {
925+
minRunningStart = action.nanoStartTime;
926+
oldestRunning = action;
927+
}
928+
} else {
929+
if (action.nanoStartTime < minScheduledStart) {
930+
minScheduledStart = action.nanoStartTime;
931+
oldestScheduled = action;
932+
}
923933
}
924934
}
925-
return result;
935+
936+
return oldestRunning != null ? oldestRunning : oldestScheduled;
926937
}
927938

928939
protected String countActions() {

src/test/java/com/google/devtools/build/lib/runtime/UiStateTrackerTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,4 +1706,30 @@ public void testTestAnalyzedEvent_repeated_noDuplicatedCount() throws Exception
17061706
output = terminalWriter.getTranscript();
17071707
assertThat(output).contains(" 1 / 1 tests");
17081708
}
1709+
1710+
@Test
1711+
public void testGetOldestAction_prioritizesRunningOverScheduled() throws Exception {
1712+
ManualClock clock = new ManualClock();
1713+
UiStateTracker stateTracker = getUiStateTracker(clock);
1714+
simulateExecutionPhase(stateTracker);
1715+
1716+
Action scheduledAction = mockAction("Scheduled action", "scheduled/action");
1717+
when(scheduledAction.getOwner()).thenReturn(dummyActionOwner());
1718+
stateTracker.actionStarted(new ActionStartedEvent(scheduledAction, clock.nanoTime()));
1719+
stateTracker.schedulingAction(new SchedulingActionEvent(scheduledAction, "some-strategy"));
1720+
1721+
clock.advanceMillis(1000);
1722+
Action runningAction = mockAction("Running action", "running/action");
1723+
when(runningAction.getOwner()).thenReturn(dummyActionOwner());
1724+
stateTracker.actionStarted(new ActionStartedEvent(runningAction, clock.nanoTime()));
1725+
stateTracker.runningAction(new RunningActionEvent(runningAction, "some-strategy"));
1726+
1727+
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/* discardHighlight= */ true);
1728+
stateTracker.writeProgressBar(terminalWriter, /*shortVersion= */true);
1729+
String output = terminalWriter.getTranscript();
1730+
1731+
assertThat(output).contains("Running action");
1732+
assertThat(output).contains("(2 actions, 1 running)");
1733+
assertThat(output).doesNotContain("Scheduled action");
1734+
}
17091735
}

0 commit comments

Comments
 (0)