-
Notifications
You must be signed in to change notification settings - Fork 277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register Datadog classloader as parallel capable #448
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package datadog.trace.bootstrap | ||
|
||
import spock.lang.Specification | ||
|
||
import java.util.concurrent.Phaser | ||
|
||
class DatadogClassLoaderTest extends Specification { | ||
def "DD classloader does not lock classloading around instance" () { | ||
setup: | ||
def className1 = 'some/class/Name1' | ||
def className2 = 'some/class/Name2' | ||
final URL loc = getClass().getProtectionDomain().getCodeSource().getLocation() | ||
final DatadogClassLoader ddLoader = new DatadogClassLoader(loc, loc, (ClassLoader) null) | ||
final Phaser threadHoldLockPhase = new Phaser(2) | ||
final Phaser acquireLockFromMainThreadPhase = new Phaser(2) | ||
|
||
when: | ||
final Thread thread = new Thread() { | ||
@Override | ||
void run() { | ||
synchronized (ddLoader.getClassLoadingLock(className1)) { | ||
threadHoldLockPhase.arrive() | ||
acquireLockFromMainThreadPhase.arriveAndAwaitAdvance() | ||
} | ||
} | ||
} | ||
thread.start() | ||
|
||
threadHoldLockPhase.arriveAndAwaitAdvance() | ||
synchronized (ddLoader.getClassLoadingLock(className2)) { | ||
acquireLockFromMainThreadPhase.arrive() | ||
} | ||
thread.join() | ||
boolean applicationDidNotDeadlock = true | ||
|
||
then: | ||
applicationDidNotDeadlock | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Failure of this test would result in test runs just hanging forever. Would it be possible to implement this so test actually exits on failure? E.g. using two additional threads and making 'main' thread just wait reasonable amount of time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I added another thread and used spock's timeout annotation to fail this test after 1 minute. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this method already had enough visibility to not needing this. If you remove this method tests still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Looks like a protected method is visible to spock tests. Pretty useful for avoiding this problem of escalating exposure for testing. Removing this method.