File tree Expand file tree Collapse file tree 2 files changed +37
-8
lines changed
groovy/datadog/trace/agent Expand file tree Collapse file tree 2 files changed +37
-8
lines changed Original file line number Diff line number Diff line change @@ -26,16 +26,26 @@ class InstrumenterUnloadTest extends Specification {
26
26
, [" DD_API_KEY" : API_KEY ]
27
27
, new PrintStream (testOutput))
28
28
29
- int unloadCount = 0
29
+ boolean canaryUnloaded = false
30
+ int unloadedInstrumentationCount = 0
30
31
new ByteArrayInputStream ((testOutput. toByteArray())). eachLine {
31
32
System . out. println (it)
33
+ if (it =~ / (?i)unload.*Canary/ ) {
34
+ canaryUnloaded = true
35
+ }
32
36
if (it =~ / (?i)unload.* datadog.trace.instrumentation./ ) {
33
- unloadCount ++
37
+ unloadedInstrumentationCount ++
34
38
}
35
39
}
36
40
41
+ if (! canaryUnloaded) {
42
+ System . out. println (" WARNING: Canary class was not unloaded!" )
43
+ }
44
+
37
45
then :
38
46
returnCode == 0
39
- unloadCount > 0
47
+ // skip check if we couldn't even unload our Canary class, as that
48
+ // indicates full GC didn't happen enough to trigger any unloading
49
+ ! canaryUnloaded || unloadedInstrumentationCount > 0
40
50
}
41
51
}
Original file line number Diff line number Diff line change 1
1
package jvmbootstraptest ;
2
2
3
+ import static java .util .concurrent .TimeUnit .MINUTES ;
4
+
3
5
import datadog .trace .test .util .GCUtils ;
6
+ import java .lang .management .ClassLoadingMXBean ;
7
+ import java .lang .management .ManagementFactory ;
4
8
5
9
public class UnloadingChecker {
6
- public static void main (final String [] args ) {
7
- try {
8
- GCUtils .awaitGC ();
9
- } catch (InterruptedException e ) {
10
- e .printStackTrace ();
10
+ static class Canary {}
11
+
12
+ public static void main (final String [] args ) throws Exception {
13
+ ClassLoadingMXBean classLoadingMXBean = ManagementFactory .getClassLoadingMXBean ();
14
+ long initialUnloadCount = classLoadingMXBean .getUnloadedClassCount ();
15
+
16
+ // load an isolated class which we know can be unloaded after a full GC
17
+ new IsolatingClassLoader ().loadClass ("jvmbootstraptest.UnloadingChecker$Canary" );
18
+
19
+ long waitNanos = MINUTES .toNanos (2 );
20
+ long startNanos = System .nanoTime ();
21
+
22
+ while (System .nanoTime () - startNanos < waitNanos ) {
23
+ try {
24
+ GCUtils .awaitGC ();
25
+ } catch (Throwable ignore ) {
26
+ }
27
+ if (initialUnloadCount < classLoadingMXBean .getUnloadedClassCount ()) {
28
+ break ; // some class unloading has taken place, stop and check results
29
+ }
11
30
}
12
31
}
13
32
}
You can’t perform that action at this time.
0 commit comments