11/*
2- * Copyright (c) 2022, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2022, 2024 , 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
2929import java .util .ArrayList ;
3030import java .util .List ;
3131import java .util .concurrent .TimeUnit ;
32+ import java .util .concurrent .TimeoutException ;
3233
33- import static org .testng .Assert .assertTrue ;
34+ import static org .testng .Assert .fail ;
3435
3536public class UpcallTestHelper extends NativeTestHelper {
3637
@@ -50,16 +51,18 @@ public OutputAnalyzer runInNewProcess(Class<?> target, boolean useSpec, List<Str
5051 command .add (target .getName ());
5152 command .addAll (programArgs );
5253
53- Process process = ProcessTools .createTestJavaProcessBuilder (command ).start ();
54-
55- long timeOut = (long ) (Utils .TIMEOUT_FACTOR * 1L );
56- boolean completed = process .waitFor (timeOut , TimeUnit .MINUTES );
57- assertTrue (completed , "Time out while waiting for process" );
58-
59- OutputAnalyzer output = new OutputAnalyzer (process );
60- output .outputTo (System .out );
61- output .errorTo (System .err );
62-
63- return output ;
54+ try {
55+ ProcessBuilder pb = ProcessTools .createTestJavaProcessBuilder (command );
56+ // note that it's important to use ProcessTools.startProcess here since this makes sure output streams of the
57+ // fork don't fill up, which could make the process stall while writing to stdout/stderr
58+ Process process = ProcessTools .startProcess (target .getName (), pb , null , null , 1L , TimeUnit .MINUTES );
59+ OutputAnalyzer output = new OutputAnalyzer (process );
60+ output .outputTo (System .out );
61+ output .errorTo (System .err );
62+ return output ;
63+ } catch (TimeoutException e ) {
64+ fail ("Timeout while waiting for forked process" );
65+ return null ;
66+ }
6467 }
6568}
0 commit comments