From 27d913c5d9f0159a57472027700b3fe92bc1c5f8 Mon Sep 17 00:00:00 2001 From: erik_gahlin Date: Fri, 3 Oct 2025 18:31:18 +0200 Subject: [PATCH 1/2] Initial --- test/jdk/jdk/jfr/tool/TestPrintContextual.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/jdk/jdk/jfr/tool/TestPrintContextual.java b/test/jdk/jdk/jfr/tool/TestPrintContextual.java index 15486148b9cb2..beae2e8380973 100644 --- a/test/jdk/jdk/jfr/tool/TestPrintContextual.java +++ b/test/jdk/jdk/jfr/tool/TestPrintContextual.java @@ -25,6 +25,7 @@ import java.nio.file.Files; import java.nio.file.Path; +import java.time.Instant; import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; @@ -265,6 +266,7 @@ private static void testDeepContext() throws Exception { } private static void span(int depth) { + awaitUniqueTimestamp(); SpanEvent span = new SpanEvent(); span.name = "span"; span.spanId = depth; @@ -277,6 +279,17 @@ private static void span(int depth) { span.commit(); } + private static void awaitUniqueTimestamp() { + Instant timestamp = Instant.now(); + while (timestamp.equals(Instant.now())) { + try { + Thread.sleep(1); + } catch (InterruptedException e) { + // ignore + } + } + } + // Tests that context values are only inhjected into events in the same thread. private static void testThreadedContext() throws Exception { try (Recording r = new Recording()) { From d433a73df5a7cfb5002e8346715df3a5eacff205 Mon Sep 17 00:00:00 2001 From: erik_gahlin Date: Mon, 6 Oct 2025 13:42:12 +0200 Subject: [PATCH 2/2] Rethrow --- test/jdk/jdk/jfr/tool/TestPrintContextual.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/test/jdk/jdk/jfr/tool/TestPrintContextual.java b/test/jdk/jdk/jfr/tool/TestPrintContextual.java index beae2e8380973..e6df9c7c7292f 100644 --- a/test/jdk/jdk/jfr/tool/TestPrintContextual.java +++ b/test/jdk/jdk/jfr/tool/TestPrintContextual.java @@ -265,7 +265,7 @@ private static void testDeepContext() throws Exception { } } - private static void span(int depth) { + private static void span(int depth) throws InterruptedException { awaitUniqueTimestamp(); SpanEvent span = new SpanEvent(); span.name = "span"; @@ -279,14 +279,10 @@ private static void span(int depth) { span.commit(); } - private static void awaitUniqueTimestamp() { + private static void awaitUniqueTimestamp() throws InterruptedException { Instant timestamp = Instant.now(); while (timestamp.equals(Instant.now())) { - try { - Thread.sleep(1); - } catch (InterruptedException e) { - // ignore - } + Thread.sleep(1); } }