Add timeout to datadog classloader test
This commit is contained in:
parent
2d8102c8f5
commit
e28ee5f9e8
|
@ -28,12 +28,6 @@ public class DatadogClassLoader extends URLClassLoader {
|
||||||
bootstrapProxy = new BootstrapClassLoaderProxy(new URL[] {bootstrapJarLocation}, null);
|
bootstrapProxy = new BootstrapClassLoaderProxy(new URL[] {bootstrapJarLocation}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Public for testing only */
|
|
||||||
@Override
|
|
||||||
public Object getClassLoadingLock(String className) {
|
|
||||||
return super.getClassLoadingLock(className);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getResource(String resourceName) {
|
public URL getResource(String resourceName) {
|
||||||
final URL bootstrapResource = bootstrapProxy.getResource(resourceName);
|
final URL bootstrapResource = bootstrapProxy.getResource(resourceName);
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package datadog.trace.bootstrap
|
package datadog.trace.bootstrap
|
||||||
|
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
|
import spock.lang.Timeout
|
||||||
|
|
||||||
import java.util.concurrent.Phaser
|
import java.util.concurrent.Phaser
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class DatadogClassLoaderTest extends Specification {
|
class DatadogClassLoaderTest extends Specification {
|
||||||
|
@Timeout(value = 60, unit = TimeUnit.SECONDS)
|
||||||
def "DD classloader does not lock classloading around instance" () {
|
def "DD classloader does not lock classloading around instance" () {
|
||||||
setup:
|
setup:
|
||||||
def className1 = 'some/class/Name1'
|
def className1 = 'some/class/Name1'
|
||||||
|
@ -15,7 +18,7 @@ class DatadogClassLoaderTest extends Specification {
|
||||||
final Phaser acquireLockFromMainThreadPhase = new Phaser(2)
|
final Phaser acquireLockFromMainThreadPhase = new Phaser(2)
|
||||||
|
|
||||||
when:
|
when:
|
||||||
final Thread thread = new Thread() {
|
final Thread thread1 = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
void run() {
|
void run() {
|
||||||
synchronized (ddLoader.getClassLoadingLock(className1)) {
|
synchronized (ddLoader.getClassLoadingLock(className1)) {
|
||||||
|
@ -24,13 +27,20 @@ class DatadogClassLoaderTest extends Specification {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
thread.start()
|
thread1.start()
|
||||||
|
|
||||||
threadHoldLockPhase.arriveAndAwaitAdvance()
|
final Thread thread2 = new Thread() {
|
||||||
synchronized (ddLoader.getClassLoadingLock(className2)) {
|
@Override
|
||||||
acquireLockFromMainThreadPhase.arrive()
|
void run() {
|
||||||
|
threadHoldLockPhase.arriveAndAwaitAdvance()
|
||||||
|
synchronized (ddLoader.getClassLoadingLock(className2)) {
|
||||||
|
acquireLockFromMainThreadPhase.arrive()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
thread.join()
|
thread2.start()
|
||||||
|
thread1.join()
|
||||||
|
thread2.join()
|
||||||
boolean applicationDidNotDeadlock = true
|
boolean applicationDidNotDeadlock = true
|
||||||
|
|
||||||
then:
|
then:
|
||||||
|
|
Loading…
Reference in New Issue