diff options
author | Janak Ramakrishnan <janakr@google.com> | 2016-08-18 18:20:53 +0000 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2016-08-19 09:52:46 +0000 |
commit | 2655e6dfbd9c4b893f437b1ca1279bc8dfa14e98 (patch) | |
tree | 054a2b7a0c59d01c3fe54b14466d829707373f17 /src/test/java | |
parent | 3edec78c39c617cdaa2839a7c1c047fe6c1ae7ed (diff) |
Make BuildViewTest#testErrorBelowCycle properly deterministic so that it can test what it's supposed to test, as pointed out by gregce.
--
MOS_MIGRATED_REVID=130661645
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java | 18 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java | 19 |
2 files changed, 23 insertions, 14 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java index 9d8e2badd1..de63f18eac 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.analysis; import static com.google.common.truth.Truth.assertThat; import static com.google.devtools.build.lib.testutil.MoreAsserts.assertEventCount; +import static com.google.devtools.build.lib.testutil.MoreAsserts.assertEventCountAtLeast; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -60,7 +61,6 @@ import com.google.devtools.build.skyframe.NotifyingHelper.Listener; import com.google.devtools.build.skyframe.NotifyingHelper.Order; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.TrackingAwaiter; - import java.util.Collection; import java.util.LinkedHashSet; import java.util.concurrent.CountDownLatch; @@ -437,8 +437,6 @@ public class BuildViewTest extends BuildViewTestBase { } // Regression test: cycle node depends on error. - // Note that this test can have nondeterministic behavior in Skyframe, depending on if the cycle - // is detected during the bubbling-up phase. @Test public void testErrorBelowCycle() throws Exception { scratch.file("foo/BUILD", @@ -449,6 +447,12 @@ public class BuildViewTest extends BuildViewTestBase { "sh_library(name = 'cycle2', deps = ['cycle1'])"); scratch.file("badbuild/BUILD", ""); reporter.removeHandler(failFastHandler); + injectGraphListenerForTesting( + new Listener() { + @Override + public void accept(SkyKey key, EventType type, Order order, Object context) {} + }, + /*deterministic=*/ true); try { update("//foo:top"); fail(); @@ -458,11 +462,9 @@ public class BuildViewTest extends BuildViewTestBase { assertContainsEvent("no such target '//badbuild:isweird': target 'isweird' not declared in " + "package 'badbuild'"); assertContainsEvent("and referenced by '//foo:bad'"); - if (eventCollector.count() > 1) { - assertContainsEvent("in sh_library rule //foo"); - assertContainsEvent("cycle in dependency graph"); - assertEventCount(3, eventCollector); - } + assertContainsEvent("in sh_library rule //foo"); + assertContainsEvent("cycle in dependency graph"); + assertEventCountAtLeast(2, eventCollector); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java b/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java index 37e8675f22..5a1f89e6d3 100644 --- a/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java +++ b/src/test/java/com/google/devtools/build/lib/testutil/MoreAsserts.java @@ -32,7 +32,6 @@ import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventCollector; import com.google.devtools.build.lib.events.EventKind; import com.google.devtools.build.lib.util.Pair; - import java.lang.ref.Reference; import java.lang.reflect.Field; import java.util.ArrayDeque; @@ -267,12 +266,20 @@ public class MoreAsserts { } /** - * If the specified EventCollector does not contain an event which has - * 'expectedEvent' as a substring, an informative assertion fails. Otherwise - * the matching event is returned. + * If the specified EventCollector contains an unexpected number of events, an informative + * assertion fails in the context of the specified TestCase. */ - public static Event assertContainsEvent(Iterable<Event> eventCollector, - String expectedEvent) { + public static void assertEventCountAtLeast(int minCount, EventCollector eventCollector) { + assertWithMessage(eventsToString(eventCollector)) + .that(eventCollector.count()) + .isAtLeast(minCount); + } + + /** + * If the specified EventCollector does not contain an event which has 'expectedEvent' as a + * substring, an informative assertion fails. Otherwise the matching event is returned. + */ + public static Event assertContainsEvent(Iterable<Event> eventCollector, String expectedEvent) { return assertContainsEvent(eventCollector, expectedEvent, EventKind.ALL_EVENTS); } |