2267 long start = System.nanoTime(); |
2267 long start = System.nanoTime(); |
2268 if (!p.isAlive() || p.waitFor(0, TimeUnit.MILLISECONDS)) { |
2268 if (!p.isAlive() || p.waitFor(0, TimeUnit.MILLISECONDS)) { |
2269 fail("Test failed: Process exited prematurely"); |
2269 fail("Test failed: Process exited prematurely"); |
2270 } |
2270 } |
2271 long end = System.nanoTime(); |
2271 long end = System.nanoTime(); |
2272 // give waitFor(timeout) a wide berth (200ms) |
2272 // give waitFor(timeout) a wide berth (2s) |
2273 // Old AIX machines my need a little longer. |
2273 System.out.printf(" waitFor process: delta: %d%n",(end - start) ); |
2274 if ((end - start) > 200000000L * (AIX.is() ? 2 : 1)) |
2274 |
|
2275 if ((end - start) > TimeUnit.SECONDS.toNanos(2)) |
2275 fail("Test failed: waitFor took too long (" + (end - start) + "ns)"); |
2276 fail("Test failed: waitFor took too long (" + (end - start) + "ns)"); |
2276 |
2277 |
2277 p.destroy(); |
2278 p.destroy(); |
2278 p.waitFor(); |
2279 p.waitFor(); |
2279 |
2280 |
2293 List<String> childArgs = new ArrayList<String>(javaChildArgs); |
2294 List<String> childArgs = new ArrayList<String>(javaChildArgs); |
2294 childArgs.add("sleep"); |
2295 childArgs.add("sleep"); |
2295 final Process p = new ProcessBuilder(childArgs).start(); |
2296 final Process p = new ProcessBuilder(childArgs).start(); |
2296 long start = System.nanoTime(); |
2297 long start = System.nanoTime(); |
2297 |
2298 |
2298 p.waitFor(1000, TimeUnit.MILLISECONDS); |
2299 p.waitFor(10, TimeUnit.MILLISECONDS); |
2299 |
2300 |
2300 long end = System.nanoTime(); |
2301 long end = System.nanoTime(); |
2301 if ((end - start) < 500000000) |
2302 if ((end - start) < TimeUnit.MILLISECONDS.toNanos(10)) |
2302 fail("Test failed: waitFor didn't take long enough (" + (end - start) + "ns)"); |
2303 fail("Test failed: waitFor didn't take long enough (" + (end - start) + "ns)"); |
2303 |
2304 |
2304 p.destroy(); |
2305 p.destroy(); |
2305 |
2306 |
2306 start = System.nanoTime(); |
2307 start = System.nanoTime(); |
2307 p.waitFor(1000, TimeUnit.MILLISECONDS); |
2308 p.waitFor(8, TimeUnit.SECONDS); |
2308 end = System.nanoTime(); |
2309 end = System.nanoTime(); |
2309 if ((end - start) > 900000000) |
2310 |
2310 fail("Test failed: waitFor took too long on a dead process. (" + (end - start) + "ns)"); |
2311 int exitValue = p.exitValue(); |
|
2312 |
|
2313 if ((end - start) > TimeUnit.SECONDS.toNanos(7)) |
|
2314 fail("Test failed: waitFor took too long on a dead process. (" + (end - start) + "ns)" |
|
2315 + ", exitValue: " + exitValue); |
2311 } catch (Throwable t) { unexpected(t); } |
2316 } catch (Throwable t) { unexpected(t); } |
2312 |
2317 |
2313 //---------------------------------------------------------------- |
2318 //---------------------------------------------------------------- |
2314 // Check that Process.waitFor(timeout, TimeUnit.MILLISECONDS) |
2319 // Check that Process.waitFor(timeout, TimeUnit.MILLISECONDS) |
2315 // interrupt works as expected, if interrupted while waiting. |
2320 // interrupt works as expected, if interrupted while waiting. |