1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
29
29
import java .util .ArrayList ;
30
30
import java .util .List ;
31
31
import java .util .concurrent .TimeUnit ;
32
+ import java .util .concurrent .TimeoutException ;
32
33
33
- import static org .testng .Assert .assertTrue ;
34
+ import static org .testng .Assert .fail ;
34
35
35
36
public class UpcallTestHelper extends NativeTestHelper {
36
37
@@ -50,16 +51,18 @@ public OutputAnalyzer runInNewProcess(Class<?> target, boolean useSpec, List<Str
50
51
command .add (target .getName ());
51
52
command .addAll (programArgs );
52
53
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
+ }
64
67
}
65
68
}
0 commit comments