Add timeout to datadog classloader test
MODIFY
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/DatadogClassLoader.java
dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/DatadogClassLoader.java
@@ -28,12 +28,6 @@ public class DatadogClassLoader extends URLClassLoader {
bootstrapProxy = new BootstrapClassLoaderProxy(new URL[] {bootstrapJarLocation}, null);
}
- /** Public for testing only */
- @Override
- public Object getClassLoadingLock(String className) {
- return super.getClassLoadingLock(className);
- }
-
@Override
public URL getResource(String resourceName) {
final URL bootstrapResource = bootstrapProxy.getResource(resourceName);

MODIFY
dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/DatadogClassLoaderTest.groovy
dd-java-agent/agent-bootstrap/src/test/groovy/datadog/trace/bootstrap/DatadogClassLoaderTest.groovy
package datadog.trace.bootstrap
import spock.lang.Specification
+import spock.lang.Timeout
import java.util.concurrent.Phaser
+import java.util.concurrent.TimeUnit
class DatadogClassLoaderTest extends Specification {
+ @Timeout(value = 60, unit = TimeUnit.SECONDS)
def "DD classloader does not lock classloading around instance" () {
setup:
def className1 = 'some/class/Name1'
@@ -15,7 +18,7 @@ class DatadogClassLoaderTest extends Specification {
final Phaser acquireLockFromMainThreadPhase = new Phaser(2)
when:
- final Thread thread = new Thread() {
+ final Thread thread1 = new Thread() {
@Override
void run() {
synchronized (ddLoader.getClassLoadingLock(className1)) {
@@ -24,13 +27,20 @@ class DatadogClassLoaderTest extends Specification {
}
}
}
- thread.start()
+ thread1.start()
+ final Thread thread2 = new Thread() {
+ @Override
+ void run() {
threadHoldLockPhase.arriveAndAwaitAdvance()
synchronized (ddLoader.getClassLoadingLock(className2)) {
acquireLockFromMainThreadPhase.arrive()
}
- thread.join()
+ }
+ }
+ thread2.start()
+ thread1.join()
+ thread2.join()
boolean applicationDidNotDeadlock = true
then:

Add timeout to datadog classloader test