|
62 | 62 | import java.util.LinkedHashMap;
|
63 | 63 | import java.util.List;
|
64 | 64 | import java.util.Map;
|
| 65 | +import java.util.Optional; |
65 | 66 | import java.util.PriorityQueue;
|
66 | 67 | import java.util.Set;
|
67 | 68 | import java.util.TreeMap;
|
68 | 69 | import java.util.concurrent.ConcurrentHashMap;
|
69 | 70 | import java.util.concurrent.atomic.AtomicInteger;
|
70 | 71 | import javax.annotation.Nullable;
|
| 72 | +import javax.annotation.concurrent.GuardedBy; |
71 | 73 | import javax.annotation.concurrent.ThreadSafe;
|
72 | 74 |
|
73 | 75 | /** Tracks state for the UI. */
|
@@ -228,6 +230,7 @@ private ProgressState(String id, long nanoStartTime) {
|
228 | 230 | }
|
229 | 231 | }
|
230 | 232 |
|
| 233 | + @GuardedBy("this") |
231 | 234 | private final LinkedHashMap<String, ProgressState> runningProgresses = new LinkedHashMap<>();
|
232 | 235 |
|
233 | 236 | /** Starts tracking the state of an action. */
|
@@ -333,6 +336,13 @@ synchronized void onProgressEvent(ActionProgressEvent event, long nanoChangeTime
|
333 | 336 | state.latestEvent = event;
|
334 | 337 | }
|
335 | 338 |
|
| 339 | + synchronized Optional<ProgressState> firstProgress() { |
| 340 | + if (runningProgresses.isEmpty()) { |
| 341 | + return Optional.empty(); |
| 342 | + } |
| 343 | + return Optional.of(runningProgresses.entrySet().iterator().next().getValue()); |
| 344 | + } |
| 345 | + |
336 | 346 | /** Generates a human-readable description of this action's state. */
|
337 | 347 | synchronized String describe() {
|
338 | 348 | if (runningStrategiesBitmap != 0) {
|
@@ -705,12 +715,12 @@ private String describeTestGroup(
|
705 | 715 | }
|
706 | 716 |
|
707 | 717 | private String describeActionProgress(ActionState action, int desiredWidth) {
|
708 |
| - if (action.runningProgresses.isEmpty()) { |
| 718 | + Optional<ActionState.ProgressState> stateOpt = action.firstProgress(); |
| 719 | + if (!stateOpt.isPresent()) { |
709 | 720 | return "";
|
710 | 721 | }
|
711 | 722 |
|
712 |
| - ActionState.ProgressState state = |
713 |
| - action.runningProgresses.entrySet().iterator().next().getValue(); |
| 723 | + ActionState.ProgressState state = stateOpt.get(); |
714 | 724 | ActionProgressEvent event = state.latestEvent;
|
715 | 725 | String message = event.progress();
|
716 | 726 | if (message.isEmpty()) {
|
|
0 commit comments