OpenJDK / jdk / jdk
changeset 56279:b35771556cd0
8230850: Test sun/tools/jcmd/TestProcessHelper.java fails intermittently
Reviewed-by: stuefe, cjplummer, sgehwolf
author | clanger |
---|---|
date | Mon, 16 Sep 2019 09:21:42 +0200 |
parents | 24df796eef3d |
children | d003b3ef8b60 |
files | test/jdk/sun/tools/jcmd/TestProcessHelper.java |
diffstat | 1 files changed, 20 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/test/jdk/sun/tools/jcmd/TestProcessHelper.java Sun Sep 15 21:00:15 2019 -0400 +++ b/test/jdk/sun/tools/jcmd/TestProcessHelper.java Mon Sep 16 09:21:42 2019 +0200 @@ -189,6 +189,26 @@ private void checkMainClass(Process p, String expectedMainClass) { String mainClass = PROCESS_HELPER.getMainClass(Long.toString(p.pid())); + // getMainClass() may return null, e.g. due to timing issues. + // Attempt some limited retries. + if (mainClass == null) { + System.err.println("Main class returned by ProcessHelper was null."); + // sleep time doubles each round, altogether, wait no longer than 1 sec + final int MAX_RETRIES = 10; + int retrycount = 0; + long sleepms = 1; + while (retrycount < MAX_RETRIES && mainClass == null) { + System.err.println("Retry " + retrycount + ", sleeping for " + sleepms + "ms."); + try { + Thread.sleep(sleepms); + } catch (InterruptedException e) { + // ignore + } + mainClass = PROCESS_HELPER.getMainClass(Long.toString(p.pid())); + retrycount++; + sleepms *= 2; + } + } p.destroyForcibly(); if (!expectedMainClass.equals(mainClass)) { throw new RuntimeException("Main class is wrong: " + mainClass);