diff --git a/test/jdk/jdk/jfr/api/consumer/streaming/TestJVMExit.java b/test/jdk/jdk/jfr/api/consumer/streaming/TestJVMExit.java index 5b30a52e4b7..77eba735d7a 100644 --- a/test/jdk/jdk/jfr/api/consumer/streaming/TestJVMExit.java +++ b/test/jdk/jdk/jfr/api/consumer/streaming/TestJVMExit.java @@ -34,12 +34,29 @@ import jdk.jfr.consumer.EventStream; * @requires vm.hasJFR * @library /test/lib /test/jdk * @modules jdk.jfr jdk.attach java.base/jdk.internal.misc + * @build jdk.jfr.api.consumer.streaming.TestProcess * * @run main/othervm -Dsun.tools.attach.attachTimeout=100000 jdk.jfr.api.consumer.streaming.TestJVMExit */ public class TestJVMExit { public static void main(String... args) throws Exception { + while (true) { + try { + testExit(); + return; + } catch (RuntimeException e) { + String message = String.valueOf(e.getMessage()); + // If the test application crashes during startup, retry. + if (!message.contains("is no longer alive")) { + throw e; + } + System.out.println("Application not alive when trying to get repository. Retrying."); + } + } + } + + private static void testExit() throws Exception { try (TestProcess process = new TestProcess("exit-application")) { AtomicInteger eventCounter = new AtomicInteger(); try (EventStream es = EventStream.openRepository(process.getRepository())) {