Fix flaky jfr metrics test (#8183)
https://ge.opentelemetry.io/s/svewzdm7cppaa/tests/:instrumentation:runtime-telemetry-jfr:library:testPS/io.opentelemetry.instrumentation.runtimetelemetryjfr.PsGcMemoryMetricTest/shouldHaveGcDurationMetrics()?top-execution=1
This commit is contained in:
parent
70cd8464e2
commit
8c7a8e1dfb
|
@ -32,6 +32,7 @@ tasks {
|
||||||
}
|
}
|
||||||
include("**/*PsGcMemoryMetricTest.*")
|
include("**/*PsGcMemoryMetricTest.*")
|
||||||
jvmArgs("-XX:+UseParallelGC")
|
jvmArgs("-XX:+UseParallelGC")
|
||||||
|
jvmArgs("-Xmx128m")
|
||||||
}
|
}
|
||||||
|
|
||||||
val testSerial by registering(Test::class) {
|
val testSerial by registering(Test::class) {
|
||||||
|
|
|
@ -76,12 +76,24 @@ class PsGcMemoryMetricTest {
|
||||||
.anyMatch(p -> p.getAttributes().equals(ATTR_PS_OLD_GEN));
|
.anyMatch(p -> p.getAttributes().equals(ATTR_PS_OLD_GEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void causeGc() {
|
||||||
|
String s = "1234567890";
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
s = s + s;
|
||||||
|
}
|
||||||
|
} catch (OutOfMemoryError outOfMemoryError) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHaveGcDurationMetrics() throws InterruptedException {
|
void shouldHaveGcDurationMetrics() {
|
||||||
// TODO: Need a reliable way to test old and young gen GC in isolation.
|
// TODO: Need a reliable way to test old and young gen GC in isolation.
|
||||||
// Generate some JFR events
|
// Generate some JFR events
|
||||||
Thread.sleep(100);
|
// using System.gc() here doesn't reliably get us the GC events we need
|
||||||
System.gc();
|
causeGc();
|
||||||
|
|
||||||
Attributes minorGcAttributes =
|
Attributes minorGcAttributes =
|
||||||
Attributes.of(ATTR_GC, "PS Scavenge", ATTR_ACTION, END_OF_MINOR_GC);
|
Attributes.of(ATTR_GC, "PS Scavenge", ATTR_ACTION, END_OF_MINOR_GC);
|
||||||
Attributes majorGcAttributes =
|
Attributes majorGcAttributes =
|
||||||
|
|
Loading…
Reference in New Issue