From 3aeefbf1defe95113a8abe3d3d11fdf3205bfd3b Mon Sep 17 00:00:00 2001 From: Leonid Mesnik Date: Wed, 1 Mar 2023 05:21:45 +0000 Subject: [PATCH] 8303421: [BACKOUT] 8303133: Update ProcessTools.startProcess(...) to exit early if process exit before linePredicate is printed. Reviewed-by: dholmes --- .../jdk/test/lib/process/ProcessTools.java | 20 ++++++------------- .../jdk/test/lib/thread/ProcessThread.java | 19 +++++++----------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/test/lib/jdk/test/lib/process/ProcessTools.java b/test/lib/jdk/test/lib/process/ProcessTools.java index 33f326f27e5..33be681c97c 100644 --- a/test/lib/jdk/test/lib/process/ProcessTools.java +++ b/test/lib/jdk/test/lib/process/ProcessTools.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -216,23 +216,15 @@ public final class ProcessTools { try { if (timeout > -1) { - // Every second check if line is printed and if process is still alive - Utils.waitForCondition(() -> latch.getCount() == 0 || !p.isAlive(), - unit.toMillis(Utils.adjustTimeout(timeout)), 1000); - - if (latch.getCount() > 0) { - if (!p.isAlive()) { - // Give some extra time for the StreamPumper to run after the process completed - Thread.sleep(1000); - if (latch.getCount() > 0) { - throw new RuntimeException("Started process " + name + " terminated before producing the expected output."); - } - } else { + if (timeout == 0) { + latch.await(); + } else { + if (!latch.await(Utils.adjustTimeout(timeout), unit)) { throw new TimeoutException(); } } } - } catch (TimeoutException | RuntimeException | InterruptedException e) { + } catch (TimeoutException | InterruptedException e) { System.err.println("Failed to start a process (thread dump follows)"); for (Map.Entry s : Thread.getAllStackTraces().entrySet()) { printStack(s.getKey(), s.getValue()); diff --git a/test/lib/jdk/test/lib/thread/ProcessThread.java b/test/lib/jdk/test/lib/thread/ProcessThread.java index 75fd76a7a04..ff4b56fd459 100644 --- a/test/lib/jdk/test/lib/thread/ProcessThread.java +++ b/test/lib/jdk/test/lib/thread/ProcessThread.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -150,21 +150,16 @@ public class ProcessThread extends TestThread { */ @Override public void xrun() throws Throwable { - try { - this.process = ProcessTools.startProcess(name, processBuilder, waitfor); - } catch (Throwable t) { - System.out.println(String.format("ProcessThread[%s] failed: %s", name, t.toString())); - throw t; - } finally { - // Release when process is started or failed - latch.countDown(); - } + this.process = ProcessTools.startProcess(name, processBuilder, waitfor); + // Release when process is started + latch.countDown(); + // Will block... try { - output = new OutputAnalyzer(this.process); - // Will block... this.process.waitFor(); + output = new OutputAnalyzer(this.process); } catch (Throwable t) { + String name = Thread.currentThread().getName(); System.out.println(String.format("ProcessThread[%s] failed: %s", name, t.toString())); throw t; } finally {