Skip to content

Commit

Permalink
[Skymeld] Set the correct test count.
Browse files Browse the repository at this point in the history
UiStateTracker was previously unaware of the Skymeld-only TestAnalyzedEvent,
which made it report the wrong total number of tests.

PiperOrigin-RevId: 468422662
Change-Id: I80660e81e1dbafaf9979487cadd63c49bf2149e9
  • Loading branch information
joeleba authored and copybara-github committed Aug 18, 2022
1 parent cff29bf commit c89cea0
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.skyframe.ConfigurationPhaseStartedEvent;
import com.google.devtools.build.lib.skyframe.LoadingPhaseStartedEvent;
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TestAnalyzedEvent;
import com.google.devtools.build.lib.util.io.AnsiTerminal;
import com.google.devtools.build.lib.util.io.AnsiTerminal.Color;
import com.google.devtools.build.lib.util.io.AnsiTerminalWriter;
Expand Down Expand Up @@ -762,6 +763,12 @@ public void testFilteringComplete(TestFilteringCompleteEvent event) {
refresh();
}

@Subscribe
public void singleTestAnalyzed(TestAnalyzedEvent event) {
stateTracker.singleTestAnalyzed(event);
refreshSoon();
}

/**
* Return true, if the test summary provides information that is both worth being shown in the
* scroll-back buffer and new with respect to the alreay shown failure messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.google.devtools.build.lib.skyframe.ConfiguredTargetProgressReceiver;
import com.google.devtools.build.lib.skyframe.LoadingPhaseStartedEvent;
import com.google.devtools.build.lib.skyframe.PackageProgressReceiver;
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TestAnalyzedEvent;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.io.AnsiTerminalWriter;
import com.google.devtools.build.lib.util.io.PositionAwareAnsiTerminalWriter;
Expand Down Expand Up @@ -952,6 +953,15 @@ synchronized void testFilteringComplete(TestFilteringCompleteEvent event) {
}
}

synchronized void singleTestAnalyzed(TestAnalyzedEvent event) {
ConfiguredTarget target = event.configuredTarget();
// Only register the count towards totalTests once.
if (target.getLabel() != null
&& testActions.putIfAbsent(target.getLabel(), Sets.newConcurrentHashSet()) == null) {
totalTests++;
}
}

public synchronized void testSummary(TestSummary summary) {
completedTests++;
mostRecentTest = summary;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ java_test(
"//src/main/java/com/google/devtools/build/lib/skyframe:configured_target_progress_receiver",
"//src/main/java/com/google/devtools/build/lib/skyframe:loading_phase_started_event",
"//src/main/java/com/google/devtools/build/lib/skyframe:package_progress_receiver",
"//src/main/java/com/google/devtools/build/lib/skyframe:top_level_status_events",
"//src/main/java/com/google/devtools/build/lib/unix",
"//src/main/java/com/google/devtools/build/lib/util",
"//src/main/java/com/google/devtools/build/lib/util:abrupt_exit_exception",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.google.devtools.build.lib.actions.SchedulingActionEvent;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
import com.google.devtools.build.lib.bazel.repository.downloader.DownloadProgressEvent;
import com.google.devtools.build.lib.buildeventstream.AnnounceBuildEventTransportsEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
Expand All @@ -61,6 +62,7 @@
import com.google.devtools.build.lib.skyframe.ConfiguredTargetProgressReceiver;
import com.google.devtools.build.lib.skyframe.LoadingPhaseStartedEvent;
import com.google.devtools.build.lib.skyframe.PackageProgressReceiver;
import com.google.devtools.build.lib.skyframe.TopLevelStatusEvents.TestAnalyzedEvent;
import com.google.devtools.build.lib.testutil.FoundationTestCase;
import com.google.devtools.build.lib.testutil.ManualClock;
import com.google.devtools.build.lib.util.DetailedExitCode;
Expand Down Expand Up @@ -1555,4 +1557,79 @@ public void waitingRemoteCacheMessage_multipleUploadEvents_countCorrectly() thro
String output = terminalWriter.getTranscript();
assertThat(output).contains("2 uploads");
}

@Test
public void testTestAnalyzedEvent() throws Exception {
// The test count should be visible in the status bar, as well as the short status bar
ManualClock clock = new ManualClock();
UiStateTracker stateTracker = getUiStateTracker(clock);
// Mimic being at the execution phase.
simulateExecutionPhase(stateTracker);
Label labelA = Label.parseCanonical("//foo:A");
ConfiguredTarget targetA = mock(ConfiguredTarget.class);
when(targetA.getLabel()).thenReturn(labelA);
TestAnalyzedEvent testAnalyzedEventA =
TestAnalyzedEvent.create(
targetA, mock(BuildConfigurationValue.class), /*isSkipped=*/ false);
Label labelB = Label.parseCanonical("//foo:B");
ConfiguredTarget targetB = mock(ConfiguredTarget.class);
when(targetB.getLabel()).thenReturn(labelB);
TestAnalyzedEvent testAnalyzedEventB =
TestAnalyzedEvent.create(
targetB, mock(BuildConfigurationValue.class), /*isSkipped=*/ false);
// Only targetA has finished running.
TestSummary testSummary = mock(TestSummary.class);
when(testSummary.getTarget()).thenReturn(targetA);
when(testSummary.getLabel()).thenReturn(labelA);

stateTracker.singleTestAnalyzed(testAnalyzedEventA);
stateTracker.singleTestAnalyzed(testAnalyzedEventB);
stateTracker.testSummary(testSummary);

LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertThat(output).contains(" 1 / 2 tests");

terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true);
output = terminalWriter.getTranscript();
assertThat(output).contains(" 1 / 2 tests");
}

@Test
public void testTestAnalyzedEvent_repeated_noDuplicatedCount() throws Exception {
// The test count should be visible in the status bar, as well as the short status bar
ManualClock clock = new ManualClock();
UiStateTracker stateTracker = getUiStateTracker(clock);
// Mimic being at the execution phase.
simulateExecutionPhase(stateTracker);
Label labelA = Label.parseCanonical("//foo:A");
ConfiguredTarget targetA = mock(ConfiguredTarget.class);
when(targetA.getLabel()).thenReturn(labelA);
TestAnalyzedEvent testAnalyzedEventA =
TestAnalyzedEvent.create(
targetA, mock(BuildConfigurationValue.class), /*isSkipped=*/ false);
TestAnalyzedEvent testAnalyzedEventARepeated =
TestAnalyzedEvent.create(
targetA, mock(BuildConfigurationValue.class), /*isSkipped=*/ false);
// Only targetA has finished running.
TestSummary testSummary = mock(TestSummary.class);
when(testSummary.getTarget()).thenReturn(targetA);
when(testSummary.getLabel()).thenReturn(labelA);

stateTracker.singleTestAnalyzed(testAnalyzedEventA);
stateTracker.singleTestAnalyzed(testAnalyzedEventARepeated);
stateTracker.testSummary(testSummary);

LoggingTerminalWriter terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
stateTracker.writeProgressBar(terminalWriter);
String output = terminalWriter.getTranscript();
assertThat(output).contains(" 1 / 1 tests");

terminalWriter = new LoggingTerminalWriter(/*discardHighlight=*/ true);
stateTracker.writeProgressBar(terminalWriter, /* shortVersion=*/ true);
output = terminalWriter.getTranscript();
assertThat(output).contains(" 1 / 1 tests");
}
}

0 comments on commit c89cea0

Please sign in to comment.