Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 1 | // Copyright 2016 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | package com.google.devtools.build.lib.runtime; |
| 15 | |
| 16 | import static org.junit.Assert.assertFalse; |
| 17 | import static org.junit.Assert.assertTrue; |
| 18 | import static org.mockito.Mockito.when; |
| 19 | |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 20 | import com.google.common.collect.ImmutableSet; |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.Action; |
| 22 | import com.google.devtools.build.lib.actions.ActionCompletionEvent; |
| 23 | import com.google.devtools.build.lib.actions.ActionStartedEvent; |
| 24 | import com.google.devtools.build.lib.actions.Artifact; |
| 25 | import com.google.devtools.build.lib.actions.Root; |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 26 | import com.google.devtools.build.lib.analysis.ConfiguredTarget; |
| 27 | import com.google.devtools.build.lib.buildtool.buildevent.TestFilteringCompleteEvent; |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 28 | import com.google.devtools.build.lib.cmdline.Label; |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 29 | import com.google.devtools.build.lib.testutil.FoundationTestCase; |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 30 | import com.google.devtools.build.lib.testutil.LoggingTerminalWriter; |
Klaus Aehlig | a63d961 | 2016-04-04 12:15:23 +0000 | [diff] [blame] | 31 | import com.google.devtools.build.lib.testutil.ManualClock; |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 32 | import com.google.devtools.build.lib.vfs.Path; |
| 33 | import com.google.devtools.build.lib.vfs.PathFragment; |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 34 | import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus; |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 35 | |
| 36 | import org.junit.Test; |
| 37 | import org.junit.runner.RunWith; |
| 38 | import org.junit.runners.JUnit4; |
| 39 | import org.mockito.Mockito; |
| 40 | |
| 41 | import java.io.IOException; |
Klaus Aehlig | e25642a | 2016-04-04 13:31:28 +0000 | [diff] [blame] | 42 | import java.util.concurrent.TimeUnit; |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 43 | |
| 44 | /** |
Klaus Aehlig | c23ba45 | 2016-04-06 12:16:39 +0000 | [diff] [blame] | 45 | * Tests {@link ExperimentalStateTracker}. |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 46 | */ |
| 47 | @RunWith(JUnit4.class) |
| 48 | public class ExperimentalStateTrackerTest extends FoundationTestCase { |
| 49 | |
| 50 | private Action mockAction(String progressMessage, String primaryOutput) { |
| 51 | Path path = outputBase.getRelative(new PathFragment(primaryOutput)); |
| 52 | Artifact artifact = new Artifact(path, Root.asSourceRoot(path)); |
| 53 | |
| 54 | Action action = Mockito.mock(Action.class); |
| 55 | when(action.getProgressMessage()).thenReturn(progressMessage); |
| 56 | when(action.getPrimaryOutput()).thenReturn(artifact); |
| 57 | return action; |
| 58 | } |
| 59 | |
Klaus Aehlig | 6d0876a | 2016-04-15 14:41:07 +0000 | [diff] [blame^] | 60 | private int longestLine(String output) { |
| 61 | int maxLength = 0; |
| 62 | for (String line : output.split("\n")) { |
| 63 | maxLength = Math.max(maxLength, line.length()); |
| 64 | } |
| 65 | return maxLength; |
| 66 | } |
| 67 | |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 68 | @Test |
| 69 | public void testActionVisible() throws IOException { |
| 70 | // If there is only one action running, it should be visible |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 71 | // somewhere in the progress bar, and also the short version thereof. |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 72 | |
| 73 | String message = "Building foo"; |
Klaus Aehlig | a63d961 | 2016-04-04 12:15:23 +0000 | [diff] [blame] | 74 | ManualClock clock = new ManualClock(); |
| 75 | clock.advanceMillis(120000); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 76 | |
Klaus Aehlig | a63d961 | 2016-04-04 12:15:23 +0000 | [diff] [blame] | 77 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 78 | stateTracker.actionStarted(new ActionStartedEvent(mockAction(message, "bar/foo"), 123456789)); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 79 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 80 | LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 81 | stateTracker.writeProgressBar(terminalWriter); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 82 | String output = terminalWriter.getTranscript(); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 83 | assertTrue( |
| 84 | "Action message '" + message + "' should be present in output: " + output, |
| 85 | output.contains(message)); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 86 | |
| 87 | terminalWriter = new LoggingTerminalWriter(); |
| 88 | stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 89 | output = terminalWriter.getTranscript(); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 90 | assertTrue( |
| 91 | "Action message '" + message + "' should be present in short output: " + output, |
| 92 | output.contains(message)); |
| 93 | |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Test |
| 97 | public void testCompletedActionNotShown() throws IOException { |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 98 | // Completed actions should not be reported in the progress bar, nor in the |
| 99 | // short progress bar. |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 100 | |
| 101 | String messageFast = "Running quick action"; |
| 102 | String messageSlow = "Running slow action"; |
| 103 | |
Klaus Aehlig | a63d961 | 2016-04-04 12:15:23 +0000 | [diff] [blame] | 104 | ManualClock clock = new ManualClock(); |
| 105 | clock.advanceMillis(120000); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 106 | Action fastAction = mockAction(messageFast, "foo/fast"); |
| 107 | Action slowAction = mockAction(messageSlow, "bar/slow"); |
Klaus Aehlig | a63d961 | 2016-04-04 12:15:23 +0000 | [diff] [blame] | 108 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 109 | stateTracker.actionStarted(new ActionStartedEvent(fastAction, 123456789)); |
| 110 | stateTracker.actionStarted(new ActionStartedEvent(slowAction, 123456999)); |
| 111 | stateTracker.actionCompletion(new ActionCompletionEvent(20, fastAction)); |
| 112 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 113 | LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 114 | stateTracker.writeProgressBar(terminalWriter); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 115 | String output = terminalWriter.getTranscript(); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 116 | assertFalse( |
| 117 | "Completed action '" + messageFast + "' should not be present in output: " + output, |
| 118 | output.contains(messageFast)); |
| 119 | assertTrue( |
| 120 | "Only running action '" + messageSlow + "' should be present in output: " + output, |
| 121 | output.contains(messageSlow)); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 122 | |
| 123 | terminalWriter = new LoggingTerminalWriter(); |
| 124 | stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 125 | output = terminalWriter.getTranscript(); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 126 | assertFalse( |
| 127 | "Completed action '" + messageFast + "' should not be present in short output: " + output, |
| 128 | output.contains(messageFast)); |
| 129 | assertTrue( |
| 130 | "Only running action '" + messageSlow + "' should be present in short output: " + output, |
| 131 | output.contains(messageSlow)); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | @Test |
| 135 | public void testOldestActionVisible() throws IOException { |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 136 | // The earliest-started action is always visible somehow in the progress bar |
| 137 | // and its short version. |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 138 | |
| 139 | String messageOld = "Running the first-started action"; |
| 140 | |
Klaus Aehlig | a63d961 | 2016-04-04 12:15:23 +0000 | [diff] [blame] | 141 | ManualClock clock = new ManualClock(); |
| 142 | clock.advanceMillis(120000); |
| 143 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 144 | stateTracker.actionStarted( |
| 145 | new ActionStartedEvent(mockAction(messageOld, "bar/foo"), 123456789)); |
| 146 | for (int i = 0; i < 30; i++) { |
| 147 | stateTracker.actionStarted( |
| 148 | new ActionStartedEvent( |
| 149 | mockAction("Other action " + i, "some/other/actions/number" + i), 123456790 + i)); |
| 150 | } |
| 151 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 152 | LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 153 | stateTracker.writeProgressBar(terminalWriter); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 154 | String output = terminalWriter.getTranscript(); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 155 | assertTrue( |
| 156 | "Longest running action '" + messageOld + "' should be visible in output: " + output, |
| 157 | output.contains(messageOld)); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 158 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 159 | terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 160 | stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 161 | output = terminalWriter.getTranscript(); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 162 | assertTrue( |
| 163 | "Longest running action '" + messageOld + "' should be visible in short output: " + output, |
| 164 | output.contains(messageOld)); |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 165 | } |
Klaus Aehlig | e25642a | 2016-04-04 13:31:28 +0000 | [diff] [blame] | 166 | |
| 167 | @Test |
| 168 | public void testTimesShown() throws IOException { |
| 169 | // For sufficiently long running actions, the time that has passed since their start is shown. |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 170 | // In the short version of the progress bar, this should be true at least for the oldest action. |
Klaus Aehlig | e25642a | 2016-04-04 13:31:28 +0000 | [diff] [blame] | 171 | |
| 172 | ManualClock clock = new ManualClock(); |
| 173 | clock.advanceMillis(TimeUnit.SECONDS.toMillis(123)); |
| 174 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
| 175 | clock.advanceMillis(TimeUnit.SECONDS.toMillis(2)); |
| 176 | |
| 177 | stateTracker.actionStarted( |
| 178 | new ActionStartedEvent(mockAction("First action", "foo"), clock.nanoTime())); |
| 179 | clock.advanceMillis(TimeUnit.SECONDS.toMillis(7)); |
| 180 | stateTracker.actionStarted( |
| 181 | new ActionStartedEvent(mockAction("Second action", "bar"), clock.nanoTime())); |
| 182 | clock.advanceMillis(TimeUnit.SECONDS.toMillis(20)); |
| 183 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 184 | LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | e25642a | 2016-04-04 13:31:28 +0000 | [diff] [blame] | 185 | stateTracker.writeProgressBar(terminalWriter); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 186 | String output = terminalWriter.getTranscript(); |
Klaus Aehlig | e25642a | 2016-04-04 13:31:28 +0000 | [diff] [blame] | 187 | assertTrue( |
| 188 | "Runtime of first action should be visible in output: " + output, output.contains("27s")); |
| 189 | assertTrue( |
| 190 | "Runtime of second action should be visible in output: " + output, output.contains("20s")); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 191 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 192 | terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 193 | stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 194 | output = terminalWriter.getTranscript(); |
Klaus Aehlig | c0c8884 | 2016-04-11 12:07:38 +0000 | [diff] [blame] | 195 | assertTrue( |
| 196 | "Runtime of first action should be visible in short output: " + output, |
| 197 | output.contains("27s")); |
Klaus Aehlig | e25642a | 2016-04-04 13:31:28 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Klaus Aehlig | 2ce24d4 | 2016-04-04 15:54:58 +0000 | [diff] [blame] | 200 | @Test |
| 201 | public void initialProgressBarTimeIndependent() { |
| 202 | ManualClock clock = new ManualClock(); |
| 203 | clock.advanceMillis(TimeUnit.SECONDS.toMillis(123)); |
| 204 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
| 205 | |
| 206 | assertFalse( |
| 207 | "Initial progress status should be time independent", |
| 208 | stateTracker.progressBarTimeDependent()); |
| 209 | } |
| 210 | |
| 211 | @Test |
| 212 | public void runningActionTimeIndependent() { |
| 213 | ManualClock clock = new ManualClock(); |
| 214 | clock.advanceMillis(TimeUnit.SECONDS.toMillis(123)); |
| 215 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
| 216 | clock.advanceMillis(TimeUnit.SECONDS.toMillis(1)); |
| 217 | stateTracker.actionStarted( |
| 218 | new ActionStartedEvent(mockAction("Some action", "foo"), clock.nanoTime())); |
| 219 | |
| 220 | assertTrue( |
| 221 | "Progress bar showing a running action should be time dependent", |
| 222 | stateTracker.progressBarTimeDependent()); |
| 223 | } |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 224 | |
| 225 | @Test |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 226 | public void testCountVisible() throws Exception { |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 227 | // The test count should be visible in the status bar, as well as the short status bar |
| 228 | ManualClock clock = new ManualClock(); |
| 229 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
| 230 | TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class); |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 231 | Label labelA = Label.parseAbsolute("//foo/bar:baz"); |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 232 | ConfiguredTarget targetA = Mockito.mock(ConfiguredTarget.class); |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 233 | when(targetA.getLabel()).thenReturn(labelA); |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 234 | ConfiguredTarget targetB = Mockito.mock(ConfiguredTarget.class); |
| 235 | when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(targetA, targetB)); |
| 236 | TestSummary testSummary = Mockito.mock(TestSummary.class); |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 237 | when(testSummary.getTarget()).thenReturn(targetA); |
| 238 | |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 239 | stateTracker.testFilteringComplete(filteringComplete); |
| 240 | stateTracker.testSummary(testSummary); |
| 241 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 242 | LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 243 | stateTracker.writeProgressBar(terminalWriter); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 244 | String output = terminalWriter.getTranscript(); |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 245 | assertTrue( |
| 246 | "Test count should be visible in output: " + output, output.contains(" 1 / 2 tests")); |
| 247 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 248 | terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 249 | stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 250 | output = terminalWriter.getTranscript(); |
Klaus Aehlig | d232d23 | 2016-04-13 09:51:25 +0000 | [diff] [blame] | 251 | assertTrue( |
| 252 | "Test count should be visible in short output: " + output, output.contains(" 1 / 2 tests")); |
| 253 | } |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 254 | |
| 255 | @Test |
| 256 | public void testPassedVisible() throws Exception { |
| 257 | // The last test that passed should still be visible in the long status bar. |
| 258 | ManualClock clock = new ManualClock(); |
| 259 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock); |
| 260 | TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class); |
| 261 | Label labelA = Label.parseAbsolute("//foo/bar:baz"); |
| 262 | ConfiguredTarget targetA = Mockito.mock(ConfiguredTarget.class); |
| 263 | when(targetA.getLabel()).thenReturn(labelA); |
| 264 | ConfiguredTarget targetB = Mockito.mock(ConfiguredTarget.class); |
| 265 | when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(targetA, targetB)); |
| 266 | TestSummary testSummary = Mockito.mock(TestSummary.class); |
| 267 | when(testSummary.getStatus()).thenReturn(BlazeTestStatus.PASSED); |
| 268 | when(testSummary.getTarget()).thenReturn(targetA); |
| 269 | |
| 270 | stateTracker.testFilteringComplete(filteringComplete); |
| 271 | stateTracker.testSummary(testSummary); |
| 272 | |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 273 | LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 274 | stateTracker.writeProgressBar(terminalWriter); |
Klaus Aehlig | ed453e0 | 2016-04-15 11:29:05 +0000 | [diff] [blame] | 275 | String output = terminalWriter.getTranscript(); |
Klaus Aehlig | b8d0c6b | 2016-04-13 11:06:41 +0000 | [diff] [blame] | 276 | |
| 277 | assertTrue( |
| 278 | "Label " + labelA.toString() + " should be present in progress bar: " + output, |
| 279 | output.contains(labelA.toString())); |
| 280 | } |
Klaus Aehlig | 6d0876a | 2016-04-15 14:41:07 +0000 | [diff] [blame^] | 281 | |
| 282 | private void doTestOutputLength(boolean withTest, int actions) throws Exception { |
| 283 | // If we target 70 characters, then there should be enough space to both, |
| 284 | // keep the line limit, and show the local part of the running actions and |
| 285 | // the passed test. |
| 286 | ManualClock clock = new ManualClock(); |
| 287 | ExperimentalStateTracker stateTracker = new ExperimentalStateTracker(clock, 70); |
| 288 | |
| 289 | Action foobuildAction = mockAction( |
| 290 | "Building //src/some/very/long/path/long/long/long/long/long/long/long/foo/foobuild.jar", |
| 291 | "//src/some/very/long/path/long/long/long/long/long/long/long/foo:foobuild"); |
| 292 | Action bazbuildAction = mockAction( |
| 293 | "Building //src/some/very/long/path/long/long/long/long/long/long/long/baz/bazbuild.jar", |
| 294 | "//src/some/very/long/path/long/long/long/long/long/long/long/baz:bazbuild"); |
| 295 | |
| 296 | Label bartestLabel = Label.parseAbsolute( |
| 297 | "//src/another/very/long/long/path/long/long/long/long/long/long/long/long/bars:bartest"); |
| 298 | ConfiguredTarget bartestTarget = Mockito.mock(ConfiguredTarget.class); |
| 299 | when(bartestTarget.getLabel()).thenReturn(bartestLabel); |
| 300 | |
| 301 | TestFilteringCompleteEvent filteringComplete = Mockito.mock(TestFilteringCompleteEvent.class); |
| 302 | when(filteringComplete.getTestTargets()).thenReturn(ImmutableSet.of(bartestTarget)); |
| 303 | |
| 304 | TestSummary testSummary = Mockito.mock(TestSummary.class); |
| 305 | when(testSummary.getStatus()).thenReturn(BlazeTestStatus.PASSED); |
| 306 | when(testSummary.getTarget()).thenReturn(bartestTarget); |
| 307 | |
| 308 | if (actions >= 1) { |
| 309 | stateTracker.actionStarted(new ActionStartedEvent(foobuildAction, 123456789)); |
| 310 | } |
| 311 | if (actions >= 2) { |
| 312 | stateTracker.actionStarted(new ActionStartedEvent(bazbuildAction, 123456900)); |
| 313 | } |
| 314 | if (withTest) { |
| 315 | stateTracker.testFilteringComplete(filteringComplete); |
| 316 | stateTracker.testSummary(testSummary); |
| 317 | } |
| 318 | |
| 319 | LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true); |
| 320 | stateTracker.writeProgressBar(terminalWriter); |
| 321 | String output = terminalWriter.getTranscript(); |
| 322 | |
| 323 | assertTrue( |
| 324 | "Only lines with at most 70 chars should be present in the output:\n" + output, |
| 325 | longestLine(output) <= 70); |
| 326 | if (actions >= 1) { |
| 327 | assertTrue( |
| 328 | "Running action 'foobuild' should be mentioned in output:\n" + output, |
| 329 | output.contains("foobuild")); |
| 330 | } |
| 331 | if (actions >= 2) { |
| 332 | assertTrue( |
| 333 | "Running action 'bazbuild' should be mentioned in output:\n" + output, |
| 334 | output.contains("bazbuild")); |
| 335 | } |
| 336 | if (withTest) { |
| 337 | assertTrue( |
| 338 | "Passed test ':bartest' should be mentioned in output:\n" + output, |
| 339 | output.contains(":bartest")); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | @Test |
| 344 | public void testOutputLength() throws Exception { |
| 345 | for (int i = 0; i < 3; i++) { |
| 346 | doTestOutputLength(true, i); |
| 347 | doTestOutputLength(false, i); |
| 348 | } |
| 349 | } |
Klaus Aehlig | 8cad4bd | 2016-03-14 11:13:58 +0000 | [diff] [blame] | 350 | } |