Skip to content

Commit cffde51

Browse files
committed
Add funky locking to ensure consistent execution for jetty test.
1 parent fb133c8 commit cffde51

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

dd-java-agent-ittests/src/test/groovy/com/datadoghq/agent/integration/servlet/JettyServletTest.groovy

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
package com.datadoghq.agent.integration.servlet
22

3+
import com.datadoghq.trace.DDBaseSpan
34
import com.datadoghq.trace.DDTags
45
import com.datadoghq.trace.DDTracer
56
import com.datadoghq.trace.writer.ListWriter
67
import io.opentracing.tag.Tags
78
import io.opentracing.util.GlobalTracer
9+
import okhttp3.Interceptor
810
import okhttp3.OkHttpClient
911
import okhttp3.Request
12+
import okhttp3.Response
1013
import org.eclipse.jetty.server.Server
1114
import org.eclipse.jetty.servlet.ServletContextHandler
1215
import spock.lang.Specification
1316
import spock.lang.Unroll
1417

1518
import java.lang.reflect.Field
19+
import java.util.concurrent.CountDownLatch
1620

1721
class JettyServletTest extends Specification {
1822

1923
static final int PORT = randomOpenPort()
24+
25+
// Jetty needs this to ensure consistent ordering for async.
26+
static CountDownLatch latch
2027
OkHttpClient client = new OkHttpClient.Builder()
28+
.addNetworkInterceptor(new Interceptor() {
29+
@Override
30+
Response intercept(Interceptor.Chain chain) throws IOException {
31+
def response = chain.proceed(chain.request())
32+
JettyServletTest.latch.await()
33+
return response
34+
}
35+
})
2136
// Uncomment when debugging:
2237
// .connectTimeout(1, TimeUnit.HOURS)
2338
// .writeTimeout(1, TimeUnit.HOURS)
@@ -27,7 +42,13 @@ class JettyServletTest extends Specification {
2742
private Server jettyServer
2843
private ServletContextHandler servletContext
2944

30-
ListWriter writer = new ListWriter()
45+
ListWriter writer = new ListWriter() {
46+
@Override
47+
void write(final List<DDBaseSpan<?>> trace) {
48+
add(trace)
49+
JettyServletTest.latch.countDown()
50+
}
51+
}
3152
DDTracer tracer = new DDTracer(writer)
3253

3354
def setup() {
@@ -63,6 +84,7 @@ class JettyServletTest extends Specification {
6384
@Unroll
6485
def "test #path servlet call"() {
6586
setup:
87+
latch = new CountDownLatch(1)
6688
def request = new Request.Builder()
6789
.url("http://localhost:$PORT/$path")
6890
.get()

dd-java-agent/src/main/java/com/datadoghq/agent/InstrumentationRulesManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public static void registerClassLoad(final Object obj) {
8080
final ClassLoader cl;
8181
if (obj instanceof ClassLoader) {
8282
cl = (ClassLoader) obj;
83-
log.info("Calling initialize with {}", cl);
83+
log.debug("Calling initialize with {}", cl);
8484
} else {
8585
cl = obj.getClass().getClassLoader();
86-
log.info("Calling initialize with {} and classloader ", obj, cl);
86+
log.debug("Calling initialize with {} and classloader {}", obj, cl);
8787
}
8888

8989
AgentRulesManager.INSTANCE.instrumentationRulesManager.initialize(cl);

0 commit comments

Comments
 (0)