Add timeout to datadog classloader test

This commit is contained in:
Andrew Kent 2018-08-20 11:10:08 -07:00
parent 2d8102c8f5
commit e28ee5f9e8
2 changed files with 16 additions and 12 deletions

View File

@ -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);

View File

@ -1,10 +1,13 @@
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()
threadHoldLockPhase.arriveAndAwaitAdvance()
synchronized (ddLoader.getClassLoadingLock(className2)) {
acquireLockFromMainThreadPhase.arrive()
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: