Skip to content

Commit

Permalink
Fix sporadic test failure (open-telemetry#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored May 12, 2020
1 parent 3a4483a commit 55211cc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
20 changes: 20 additions & 0 deletions testing/src/test/groovy/context/FieldBackedProviderTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion testing/src/test/java/context/ContextTestInstrumentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions testing/testing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ tasks.register("testDisabledFieldInjection", Test) {
include "context/FieldBackedProviderFieldInjectionDisabledTest.class"
}
test.dependsOn(testDisabledFieldInjection)

test.forkEvery = 1

0 comments on commit 55211cc

Please sign in to comment.