From 55211ccd732fe5ef5a43664ccd180e3050a9f763 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Mon, 11 May 2020 20:53:49 -0700 Subject: [PATCH] Fix sporadic test failure (#386) --- .../context/FieldBackedProviderTest.groovy | 20 +++++++++++++++++++ .../context/ContextTestInstrumentation.java | 10 +++++++++- testing/testing.gradle | 2 ++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/testing/src/test/groovy/context/FieldBackedProviderTest.groovy b/testing/src/test/groovy/context/FieldBackedProviderTest.groovy index 1d80a87d131c..fb05d979d6a4 100644 --- a/testing/src/test/groovy/context/FieldBackedProviderTest.groovy +++ b/testing/src/test/groovy/context/FieldBackedProviderTest.groovy @@ -40,6 +40,10 @@ import static context.ContextTestInstrumentation.UntransformableKeyClass class FieldBackedProviderTest extends AgentTestRunner { + static { + System.setProperty("ota.integration.context-test-instrumentation.enabled", "true") + } + @Override boolean onInstrumentationError( final String typeName, @@ -206,6 +210,22 @@ class FieldBackedProviderTest extends AgentTestRunner { */ @Requires({ "false" == System.getProperty("ota.trace.runtime.context.field.injection") }) class FieldBackedProviderFieldInjectionDisabledTest extends AgentTestRunner { + + static { + System.setProperty("ota.integration.context-test-instrumentation.enabled", "true") + } + + @Override + boolean onInstrumentationError( + final String typeName, + final ClassLoader classLoader, + final JavaModule module, + final boolean loaded, + final Throwable throwable) { + // Incorrect* classes assert on incorrect api usage. Error expected. + return !(typeName.startsWith(ContextTestInstrumentation.getName() + '$Incorrect') && throwable.getMessage().startsWith("Incorrect Context Api Usage detected.")) + } + def "Check that structure is not modified when structure modification is disabled"() { setup: def keyClass = ContextTestInstrumentation.DisabledKeyClass diff --git a/testing/src/test/java/context/ContextTestInstrumentation.java b/testing/src/test/java/context/ContextTestInstrumentation.java index ef16ec61b905..eee18cd468a2 100644 --- a/testing/src/test/java/context/ContextTestInstrumentation.java +++ b/testing/src/test/java/context/ContextTestInstrumentation.java @@ -32,7 +32,15 @@ @AutoService(Instrumenter.class) public class ContextTestInstrumentation extends Instrumenter.Default { public ContextTestInstrumentation() { - super("context-test-isntrumenter1"); + super("context-test-instrumentation"); + } + + @Override + protected boolean defaultEnabled() { + // this instrumentation is disabled by default, so that it doesn't cause sporadic failures + // in other tests that do override AgentTestRunner.onInstrumentationError() to filter out + // the instrumentation errors that this instrumentation purposefully introduces + return false; } @Override diff --git a/testing/testing.gradle b/testing/testing.gradle index c6eb05b9e51f..309922f6112c 100644 --- a/testing/testing.gradle +++ b/testing/testing.gradle @@ -62,3 +62,5 @@ tasks.register("testDisabledFieldInjection", Test) { include "context/FieldBackedProviderFieldInjectionDisabledTest.class" } test.dependsOn(testDisabledFieldInjection) + +test.forkEvery = 1