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;
|
||||
|
||||
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.extension.RegisterExtension;
|
||||
|
||||
|
@ -19,12 +22,31 @@ class JfrCpuLockTest {
|
|||
|
||||
@Test
|
||||
void shouldHaveLockEvents() throws Exception {
|
||||
// This should generate some events
|
||||
System.gc();
|
||||
synchronized (this) {
|
||||
Thread.sleep(1000);
|
||||
AtomicBoolean done = new AtomicBoolean(false);
|
||||
synchronized (done) {
|
||||
new Thread(
|
||||
() -> {
|
||||
try {
|
||||
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(
|
||||
metric ->
|
||||
metric
|
||||
|
|
Loading…
Reference in New Issue