Skip to content

Commit 3aeefbf

Browse files
committed
8303421: [BACKOUT] 8303133: Update ProcessTools.startProcess(...) to exit early if process exit before linePredicate is printed.
Reviewed-by: dholmes
1 parent 1fdaf25 commit 3aeefbf

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

test/lib/jdk/test/lib/process/ProcessTools.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -216,23 +216,15 @@ protected void processLine(String line) {
216216

217217
try {
218218
if (timeout > -1) {
219-
// Every second check if line is printed and if process is still alive
220-
Utils.waitForCondition(() -> latch.getCount() == 0 || !p.isAlive(),
221-
unit.toMillis(Utils.adjustTimeout(timeout)), 1000);
222-
223-
if (latch.getCount() > 0) {
224-
if (!p.isAlive()) {
225-
// Give some extra time for the StreamPumper to run after the process completed
226-
Thread.sleep(1000);
227-
if (latch.getCount() > 0) {
228-
throw new RuntimeException("Started process " + name + " terminated before producing the expected output.");
229-
}
230-
} else {
219+
if (timeout == 0) {
220+
latch.await();
221+
} else {
222+
if (!latch.await(Utils.adjustTimeout(timeout), unit)) {
231223
throw new TimeoutException();
232224
}
233225
}
234226
}
235-
} catch (TimeoutException | RuntimeException | InterruptedException e) {
227+
} catch (TimeoutException | InterruptedException e) {
236228
System.err.println("Failed to start a process (thread dump follows)");
237229
for (Map.Entry<Thread, StackTraceElement[]> s : Thread.getAllStackTraces().entrySet()) {
238230
printStack(s.getKey(), s.getValue());

test/lib/jdk/test/lib/thread/ProcessThread.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -150,21 +150,16 @@ public ProcessRunnable(ProcessBuilder pb, String name, Predicate<String> waitfor
150150
*/
151151
@Override
152152
public void xrun() throws Throwable {
153-
try {
154-
this.process = ProcessTools.startProcess(name, processBuilder, waitfor);
155-
} catch (Throwable t) {
156-
System.out.println(String.format("ProcessThread[%s] failed: %s", name, t.toString()));
157-
throw t;
158-
} finally {
159-
// Release when process is started or failed
160-
latch.countDown();
161-
}
153+
this.process = ProcessTools.startProcess(name, processBuilder, waitfor);
154+
// Release when process is started
155+
latch.countDown();
162156

157+
// Will block...
163158
try {
164-
output = new OutputAnalyzer(this.process);
165-
// Will block...
166159
this.process.waitFor();
160+
output = new OutputAnalyzer(this.process);
167161
} catch (Throwable t) {
162+
String name = Thread.currentThread().getName();
168163
System.out.println(String.format("ProcessThread[%s] failed: %s", name, t.toString()));
169164
throw t;
170165
} finally {

0 commit comments

Comments
 (0)