ExperimentalStateTracker: add a short version of the progress bar
When bazel is used without curses, every status message ever written
will never be deleted and, instead, stick in the log. To keep the output
manageable in this case, provide a one-line progress bar to be used in
this case.
--
Change-Id: Ia0f9619d406e676f88ff536617a56fd4990cb51e
Reviewed-on: https://bazel-review.googlesource.com/#/c/3294
MOS_MIGRATED_REVID=119520912
diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java
index c3c0a68..eaf4a50 100644
--- a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java
@@ -93,7 +93,7 @@
@Test
public void testActionVisible() throws IOException {
// If there is only one action running, it should be visible
- // somewhere in the progress bar.
+ // somewhere in the progress bar, and also the short version thereof.
String message = "Building foo";
ManualClock clock = new ManualClock();
@@ -101,18 +101,27 @@
ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock);
stateTracker.actionStarted(new ActionStartedEvent(mockAction(message, "bar/foo"), 123456789));
+
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter();
stateTracker.writeProgressBar(terminalWriter);
-
String output = terminalWriter.getWritten();
assertTrue(
"Action message '" + message + "' should be present in output: " + output,
output.contains(message));
+
+ terminalWriter = new LoggingTerminalWriter();
+ stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true);
+ output = terminalWriter.getWritten();
+ assertTrue(
+ "Action message '" + message + "' should be present in short output: " + output,
+ output.contains(message));
+
}
@Test
public void testCompletedActionNotShown() throws IOException {
- // Completed actions should not be reported in the progress bar.
+ // Completed actions should not be reported in the progress bar, nor in the
+ // short progress bar.
String messageFast = "Running quick action";
String messageSlow = "Running slow action";
@@ -128,7 +137,6 @@
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter();
stateTracker.writeProgressBar(terminalWriter);
-
String output = terminalWriter.getWritten();
assertFalse(
"Completed action '" + messageFast + "' should not be present in output: " + output,
@@ -136,11 +144,22 @@
assertTrue(
"Only running action '" + messageSlow + "' should be present in output: " + output,
output.contains(messageSlow));
+
+ terminalWriter = new LoggingTerminalWriter();
+ stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true);
+ output = terminalWriter.getWritten();
+ assertFalse(
+ "Completed action '" + messageFast + "' should not be present in short output: " + output,
+ output.contains(messageFast));
+ assertTrue(
+ "Only running action '" + messageSlow + "' should be present in short output: " + output,
+ output.contains(messageSlow));
}
@Test
public void testOldestActionVisible() throws IOException {
- // The earliest-started action is always visible somehow in the progress bar.
+ // The earliest-started action is always visible somehow in the progress bar
+ // and its short version.
String messageOld = "Running the first-started action";
@@ -157,16 +176,23 @@
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter();
stateTracker.writeProgressBar(terminalWriter);
-
String output = terminalWriter.getWritten();
assertTrue(
"Longest running action '" + messageOld + "' should be visible in output: " + output,
output.contains(messageOld));
+
+ terminalWriter = new LoggingTerminalWriter();
+ stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true);
+ output = terminalWriter.getWritten();
+ assertTrue(
+ "Longest running action '" + messageOld + "' should be visible in short output: " + output,
+ output.contains(messageOld));
}
@Test
public void testTimesShown() throws IOException {
// For sufficiently long running actions, the time that has passed since their start is shown.
+ // In the short version of the progress bar, this should be true at least for the oldest action.
ManualClock clock = new ManualClock();
clock.advanceMillis(TimeUnit.SECONDS.toMillis(123));
@@ -183,11 +209,17 @@
LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter();
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getWritten();
-
assertTrue(
"Runtime of first action should be visible in output: " + output, output.contains("27s"));
assertTrue(
"Runtime of second action should be visible in output: " + output, output.contains("20s"));
+
+ terminalWriter = new LoggingTerminalWriter();
+ stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true);
+ output = terminalWriter.getWritten();
+ assertTrue(
+ "Runtime of first action should be visible in short output: " + output,
+ output.contains("27s"));
}
@Test