Skip to content

Commit

Permalink
Fix flaky runtime metrics close test
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit committed Jun 5, 2023
1 parent 65c5972 commit 88fa2ec
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void builder() {
}

@Test
void close() {
void close() throws InterruptedException {
try (RuntimeMetrics jfrTelemetry = RuntimeMetrics.builder(sdk).build()) {
// Track whether RecordingStream has been closed
AtomicBoolean recordingStreamClosed = new AtomicBoolean(false);
Expand All @@ -92,11 +92,13 @@ void close() {
jfrTelemetry.close();
logs.assertDoesNotContain("RuntimeMetrics is already closed");
assertThat(recordingStreamClosed.get()).isTrue();
assertThat(reader.collectAllMetrics())
.allSatisfy(
metric -> {
assertThat(metric.getName()).isEqualTo("process.runtime.jvm.gc.duration");
});

// clear all metrics that might have arrived after close
Thread.sleep(100); // give time for any inflight metric export to be received
reader.collectAllMetrics();

Thread.sleep(100);
assertThat(reader.collectAllMetrics()).isEmpty();

jfrTelemetry.close();
logs.assertContains("RuntimeMetrics is already closed");
Expand Down

0 comments on commit 88fa2ec

Please sign in to comment.