Fix JFR lock wait test (#8494)
This commit is contained in:
parent
eb77991e5d
commit
30fc14e247
|
@ -6,7 +6,10 @@
|
||||||
package io.opentelemetry.instrumentation.runtimemetrics.java17;
|
package io.opentelemetry.instrumentation.runtimemetrics.java17;
|
||||||
|
|
||||||
import static io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants.MILLISECONDS;
|
import static io.opentelemetry.instrumentation.runtimemetrics.java17.internal.Constants.MILLISECONDS;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
@ -19,11 +22,30 @@ class JfrCpuLockTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void shouldHaveLockEvents() throws Exception {
|
void shouldHaveLockEvents() throws Exception {
|
||||||
// This should generate some events
|
AtomicBoolean done = new AtomicBoolean(false);
|
||||||
System.gc();
|
synchronized (done) {
|
||||||
synchronized (this) {
|
new Thread(
|
||||||
|
() -> {
|
||||||
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException exception) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
}
|
}
|
||||||
|
synchronized (done) {
|
||||||
|
done.set(true);
|
||||||
|
done.notifyAll();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.start();
|
||||||
|
long waitTime = Duration.ofSeconds(10).toMillis();
|
||||||
|
long endTime = System.currentTimeMillis() + Duration.ofSeconds(10).toMillis();
|
||||||
|
while (!done.get() && waitTime > 0) {
|
||||||
|
done.wait(waitTime);
|
||||||
|
waitTime = endTime - System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(done.get()).isEqualTo(true);
|
||||||
|
|
||||||
jfrExtension.waitAndAssertMetrics(
|
jfrExtension.waitAndAssertMetrics(
|
||||||
metric ->
|
metric ->
|
||||||
|
|
Loading…
Reference in New Issue