Merge pull request #269 from DataDog/run_single_idea_test

Remove opentracing from TestRunner fields to support Idea single test run
This commit is contained in:
Andrew Kent 2018-03-23 08:32:53 -07:00 committed by GitHub
commit 288c9e20de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 7 deletions

View File

@ -18,7 +18,7 @@ class JerseyTest extends AgentTestRunner {
def "test resource"() {
setup:
// start a trace because the test doesn't go through any servlet or other instrumentation.
def scope = TEST_TRACER.buildSpan("test.span").startActive(true)
def scope = getTestTracer().buildSpan("test.span").startActive(true)
def response = resources.client().resource("/test/hello/bob").post(String)
scope.close()

View File

@ -62,7 +62,7 @@ class KafkaStreamsTest extends AgentTestRunner {
@Override
void onMessage(ConsumerRecord<String, String> record) {
WRITER_PHASER.arriveAndAwaitAdvance() // ensure consistent ordering of traces
TEST_TRACER.activeSpan().setTag("testing", 123)
getTestTracer().activeSpan().setTag("testing", 123)
records.add(record)
}
})
@ -81,7 +81,7 @@ class KafkaStreamsTest extends AgentTestRunner {
@Override
String apply(String textLine) {
WRITER_PHASER.arriveAndAwaitAdvance() // ensure consistent ordering of traces
TEST_TRACER.activeSpan().setTag("asdf", "testing")
getTestTracer().activeSpan().setTag("asdf", "testing")
return textLine.toLowerCase()
}
})

View File

@ -7,6 +7,7 @@ import datadog.opentracing.DDTracer;
import datadog.trace.agent.tooling.AgentInstaller;
import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.common.writer.ListWriter;
import datadog.trace.common.writer.Writer;
import io.opentracing.Tracer;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
@ -52,7 +53,10 @@ public abstract class AgentTestRunner extends Specification {
*/
public static final ListWriter TEST_WRITER;
protected static final Tracer TEST_TRACER;
// having a reference to io.opentracing.Tracer in test field
// loads opentracing before bootstrap classpath is setup
// so we declare tracer as an object and cast when needed.
private static final Object TEST_TRACER;
private static final AtomicInteger INSTRUMENTATION_ERROR_COUNT = new AtomicInteger();
private static final Instrumentation instrumentation;
@ -77,7 +81,15 @@ public abstract class AgentTestRunner extends Specification {
}
};
TEST_TRACER = new DDTracer(TEST_WRITER);
TestUtils.registerOrReplaceGlobalTracer(TEST_TRACER);
TestUtils.registerOrReplaceGlobalTracer((Tracer) TEST_TRACER);
}
protected static Tracer getTestTracer() {
return (Tracer) TEST_TRACER;
}
protected static Writer getTestWriter() {
return TEST_WRITER;
}
@BeforeClass
@ -100,7 +112,7 @@ public abstract class AgentTestRunner extends Specification {
public void beforeTest() {
TEST_WRITER.start();
INSTRUMENTATION_ERROR_COUNT.set(0);
assert (TEST_TRACER).activeSpan() == null;
assert getTestTracer().activeSpan() == null;
}
@After

View File

@ -1,4 +1,5 @@
import datadog.trace.agent.test.TestUtils
import io.opentracing.Tracer
import java.lang.reflect.Field
@ -8,6 +9,8 @@ class AgentTestRunnerTest extends AgentTestRunner {
private static final ClassLoader BOOTSTRAP_CLASSLOADER = null
private static final ClassLoader OT_LOADER
private static final boolean AGENT_INSTALLED_IN_CLINIT
// having opentracing class in test field should not cause problems
private static final Tracer A_TRACER = null
static {
// when test class initializes, opentracing should be set up, but not the agent.
@ -17,9 +20,10 @@ class AgentTestRunnerTest extends AgentTestRunner {
def "classpath setup"() {
expect:
A_TRACER == null
OT_LOADER == BOOTSTRAP_CLASSLOADER
!AGENT_INSTALLED_IN_CLINIT
TEST_TRACER == TestUtils.getUnderlyingGlobalTracer()
getTestTracer() == TestUtils.getUnderlyingGlobalTracer()
getAgentTransformer() != null
datadog.trace.api.Trace.getClassLoader() == BOOTSTRAP_CLASSLOADER
}