Skip to content

Commit

Permalink
Remove redundant ManualClock implementations.
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 186036592
  • Loading branch information
cvcal authored and Copybara-Service committed Feb 16, 2018
1 parent cbf8c0a commit 950bcf7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.when;

import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.eventbus.EventBus;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.events.EventKind;
import com.google.devtools.build.lib.events.util.EventCollectionApparatus;
import com.google.devtools.build.lib.testutil.ManualClock;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -37,34 +36,11 @@
/** Test for the {@link ActionExecutionStatusReporter} class. */
@RunWith(JUnit4.class)
public class ActionExecutionStatusReporterTest {
private static final class MockClock implements Clock {
private long millis = 0;

public void advance() {
advanceBy(1000);
}

public void advanceBy(long millis) {
Preconditions.checkArgument(millis > 0);
this.millis += millis;
}

@Override
public long currentTimeMillis() {
return millis;
}

@Override
public long nanoTime() {
// There's no reason to use a nanosecond-precision for a mock clock.
return millis * 1000000L;
}
}

private EventCollectionApparatus events;
private ActionExecutionStatusReporter statusReporter;
private EventBus eventBus;
private MockClock clock = new MockClock();
private ManualClock clock = new ManualClock();

private Action mockAction(String progressMessage) {
Action action = Mockito.mock(Action.class);
Expand Down Expand Up @@ -126,12 +102,12 @@ public void testCategories() throws Exception {
verifyNoOutput();
verifyWarningOutput("There are no active jobs - stopping the build");
setPreparing(mockAction("action1"));
clock.advance();
clock.advanceMillis(1000);
verifyWarningOutput("Still waiting for unfinished jobs");
setScheduling(mockAction("action2"));
clock.advance();
clock.advanceMillis(1000);
setRunning(mockAction("action3"), "remote");
clock.advance();
clock.advanceMillis(1000);
setRunning(mockAction("action4"), "something else");
verifyOutput("Still waiting for 4 jobs to complete:",
"Preparing:", "action1, 3 s",
Expand All @@ -150,16 +126,16 @@ public void testSingleAction() throws Exception {
Action action = mockAction("action1");
verifyNoOutput();
setPreparing(action);
clock.advanceBy(1200);
clock.advanceMillis(1200);
verifyOutput("Still waiting for 1 job to complete:", "Preparing:", "action1, 1 s");
clock.advanceBy(5000);
clock.advanceMillis(5000);

setScheduling(action);
clock.advanceBy(1200);
clock.advanceMillis(1200);
// Only started *scheduling* 1200 ms ago, not 6200 ms ago.
verifyOutput("Still waiting for 1 job to complete:", "Scheduling:", "action1, 1 s");
setRunning(action, "remote");
clock.advanceBy(3000);
clock.advanceMillis(3000);
// Only started *running* 3000 ms ago, not 4200 ms ago.
verifyOutput("Still waiting for 1 job to complete:", "Running (remote):", "action1, 3 s");
statusReporter.remove(action);
Expand All @@ -171,15 +147,15 @@ public void testDynamicUpdate() throws Exception {
Action action = mockAction("action1");
verifyNoOutput();
setPreparing(action);
clock.advance();
clock.advanceMillis(1000);
verifyOutput("Still waiting for 1 job to complete:", "Preparing:", "action1, 1 s");
setScheduling(action);
clock.advance();
clock.advanceMillis(1000);
verifyOutput("Still waiting for 1 job to complete:", "Scheduling:", "action1, 1 s");
setRunning(action, "remote");
clock.advance();
clock.advanceMillis(1000);
verifyOutput("Still waiting for 1 job to complete:", "Running (remote):", "action1, 1 s");
clock.advance();
clock.advanceMillis(1000);

eventBus.post(ActionStatusMessage.analysisStrategy(action));
// Locality strategy was changed, so timer was reset to 0 s.
Expand All @@ -197,7 +173,7 @@ public void testGroups() throws Exception {

for (Action a : actions) {
setScheduling(a);
clock.advance();
clock.advanceMillis(1000);
}

verifyOutput("Still waiting for 6 jobs to complete:",
Expand All @@ -207,7 +183,7 @@ public void testGroups() throws Exception {

for (Action a : actions) {
setRunning(a, a.getProgressMessage().startsWith("remote") ? "remote" : "something else");
clock.advanceBy(2000);
clock.advanceMillis(2000);
}

// Timers got reset because now they are no longer scheduling but running.
Expand All @@ -229,15 +205,15 @@ public void testTruncation() throws Exception {
Action a = mockAction("a" + i);
actions.add(a);
setScheduling(a);
clock.advance();
clock.advanceMillis(1000);
}
verifyOutput("Still waiting for 100 jobs to complete:", "Scheduling:",
"a1, 100 s", "a2, 99 s", "a3, 98 s", "a4, 97 s", "a5, 96 s",
"a6, 95 s", "a7, 94 s", "a8, 93 s", "a9, 92 s", "... 91 more jobs");

for (int i = 0; i < 5; i++) {
setRunning(actions.get(i), "something else");
clock.advance();
clock.advanceMillis(1000);
}
verifyOutput("Still waiting for 100 jobs to complete:",
"Running (something else):", "a1, 5 s", "a2, 4 s", "a3, 3 s", "a4, 2 s", "a5, 1 s",
Expand All @@ -249,13 +225,13 @@ public void testTruncation() throws Exception {
public void testOrdering() throws Exception {
verifyNoOutput();
setScheduling(mockAction("a1"));
clock.advance();
clock.advanceMillis(1000);
setPreparing(mockAction("b1"));
clock.advance();
clock.advanceMillis(1000);
setPreparing(mockAction("b2"));
clock.advance();
clock.advanceMillis(1000);
setScheduling(mockAction("a2"));
clock.advance();
clock.advanceMillis(1000);
verifyOutput("Still waiting for 4 jobs to complete:",
"Preparing:", "b1, 3 s", "b2, 2 s",
"Scheduling:", "a1, 4 s", "a2, 1 s");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import static com.google.common.truth.Truth.assertWithMessage;

import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.skyframe.FileArtifactValue;
import com.google.devtools.build.lib.testutil.ManualClock;
import com.google.devtools.build.lib.testutil.Scratch;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
Expand All @@ -32,20 +32,6 @@
@RunWith(JUnit4.class)
public class CompactPersistentActionCacheTest {

private static class ManualClock implements Clock {
private long currentTime = 0L;

ManualClock() { }

@Override public long currentTimeMillis() {
return currentTime;
}

@Override public long nanoTime() {
return 0;
}
}

private Scratch scratch = new Scratch();
private Path dataRoot;
private Path mapFile;
Expand Down

0 comments on commit 950bcf7

Please sign in to comment.