-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathInstrumenterUnloadTest.groovy
More file actions
51 lines (43 loc) · 1.53 KB
/
InstrumenterUnloadTest.groovy
File metadata and controls
51 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package datadog.trace.agent
import datadog.trace.agent.test.IntegrationTestUtils
import jvmbootstraptest.UnloadingChecker
import spock.lang.Specification
import spock.lang.Timeout
@Timeout(30)
class InstrumenterUnloadTest extends Specification {
private static final String DEFAULT_LOG_LEVEL = "debug"
private static final String API_KEY = "01234567890abcdef123456789ABCDEF"
// Run test using forked jvm
def "instrumenter and muzzle classes can be unloaded after use"() {
setup:
def testOutput = new ByteArrayOutputStream()
when:
int returnCode = IntegrationTestUtils.runOnSeparateJvm(UnloadingChecker.getName()
, [
"-verbose:class",
"-Ddatadog.slf4j.simpleLogger.defaultLogLevel=$DEFAULT_LOG_LEVEL"
] as String[]
, "" as String[]
, ["DD_API_KEY": API_KEY]
, new PrintStream(testOutput))
boolean canaryUnloaded = false
int unloadedInstrumentationCount = 0
new ByteArrayInputStream((testOutput.toByteArray())).eachLine {
System.out.println(it)
if (it =~ /(?i)unload.*Canary/) {
canaryUnloaded = true
}
if (it =~ /(?i)unload.* datadog.trace.instrumentation./) {
unloadedInstrumentationCount++
}
}
if (!canaryUnloaded) {
System.out.println("WARNING: Canary class was not unloaded!")
}
then:
returnCode == 0
// skip check if we couldn't even unload our Canary class, as that
// indicates full GC didn't happen enough to trigger any unloading
!canaryUnloaded || unloadedInstrumentationCount > 0
}
}