Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote: Fix a race when reporting action progresses. #13719

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;

/** Tracks state for the UI. */
Expand Down Expand Up @@ -228,6 +230,7 @@ private ProgressState(String id, long nanoStartTime) {
}
}

@GuardedBy("this")
private final LinkedHashMap<String, ProgressState> runningProgresses = new LinkedHashMap<>();

/** Starts tracking the state of an action. */
Expand Down Expand Up @@ -333,6 +336,13 @@ synchronized void onProgressEvent(ActionProgressEvent event, long nanoChangeTime
state.latestEvent = event;
}

synchronized Optional<ProgressState> firstProgress() {
if (runningProgresses.isEmpty()) {
return Optional.empty();
}
return Optional.of(runningProgresses.entrySet().iterator().next().getValue());
}

/** Generates a human-readable description of this action's state. */
synchronized String describe() {
if (runningStrategiesBitmap != 0) {
Expand Down Expand Up @@ -705,12 +715,12 @@ private String describeTestGroup(
}

private String describeActionProgress(ActionState action, int desiredWidth) {
if (action.runningProgresses.isEmpty()) {
Optional<ActionState.ProgressState> stateOpt = action.firstProgress();
if (!stateOpt.isPresent()) {
return "";
}

ActionState.ProgressState state =
action.runningProgresses.entrySet().iterator().next().getValue();
ActionState.ProgressState state = stateOpt.get();
ActionProgressEvent event = state.latestEvent;
String message = event.progress();
if (message.isEmpty()) {
Expand Down