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);
|
||||
}
|
||||
|
||||
/** 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);
|
||||
|
|
|
@ -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()
|
||||
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue