2241 }
2242 } catch (Throwable t) { unexpected(t); }
2243
2244 //----------------------------------------------------------------
2245 // Check that Process.waitFor(timeout, TimeUnit.MILLISECONDS)
2246 // works as expected.
2247 //----------------------------------------------------------------
2248 try {
2249 List<String> childArgs = new ArrayList<String>(javaChildArgs);
2250 childArgs.add("sleep");
2251 final Process p = new ProcessBuilder(childArgs).start();
2252 long start = System.nanoTime();
2253
2254 p.waitFor(10, TimeUnit.MILLISECONDS);
2255
2256 long end = System.nanoTime();
2257 if ((end - start) < TimeUnit.MILLISECONDS.toNanos(10))
2258 fail("Test failed: waitFor didn't take long enough (" + (end - start) + "ns)");
2259
2260 p.destroy();
2261
2262 start = System.nanoTime();
2263 p.waitFor(8, TimeUnit.SECONDS);
2264 end = System.nanoTime();
2265
2266 int exitValue = p.exitValue();
2267
2268 if ((end - start) > TimeUnit.SECONDS.toNanos(7))
2269 fail("Test failed: waitFor took too long on a dead process. (" + (end - start) + "ns)"
2270 + ", exitValue: " + exitValue);
2271 } catch (Throwable t) { unexpected(t); }
2272
2273 //----------------------------------------------------------------
2274 // Check that Process.waitFor(timeout, TimeUnit.MILLISECONDS)
2275 // interrupt works as expected, if interrupted while waiting.
2276 //----------------------------------------------------------------
2277 try {
2278 List<String> childArgs = new ArrayList<String>(javaChildArgs);
2279 childArgs.add("sleep");
2280 final Process p = new ProcessBuilder(childArgs).start();
2281 final long start = System.nanoTime();
2282 final CountDownLatch aboutToWaitFor = new CountDownLatch(1);
2283
2284 final Thread thread = new Thread() {
2285 public void run() {
2286 try {
2287 aboutToWaitFor.countDown();
2288 Thread.currentThread().interrupt();
2289 boolean result = p.waitFor(30L * 1000L, TimeUnit.MILLISECONDS);
2290 fail("waitFor() wasn't interrupted, its return value was: " + result);
|
2241 }
2242 } catch (Throwable t) { unexpected(t); }
2243
2244 //----------------------------------------------------------------
2245 // Check that Process.waitFor(timeout, TimeUnit.MILLISECONDS)
2246 // works as expected.
2247 //----------------------------------------------------------------
2248 try {
2249 List<String> childArgs = new ArrayList<String>(javaChildArgs);
2250 childArgs.add("sleep");
2251 final Process p = new ProcessBuilder(childArgs).start();
2252 long start = System.nanoTime();
2253
2254 p.waitFor(10, TimeUnit.MILLISECONDS);
2255
2256 long end = System.nanoTime();
2257 if ((end - start) < TimeUnit.MILLISECONDS.toNanos(10))
2258 fail("Test failed: waitFor didn't take long enough (" + (end - start) + "ns)");
2259
2260 p.destroy();
2261 } catch (Throwable t) { unexpected(t); }
2262
2263 //----------------------------------------------------------------
2264 // Check that Process.waitFor(timeout, TimeUnit.MILLISECONDS)
2265 // interrupt works as expected, if interrupted while waiting.
2266 //----------------------------------------------------------------
2267 try {
2268 List<String> childArgs = new ArrayList<String>(javaChildArgs);
2269 childArgs.add("sleep");
2270 final Process p = new ProcessBuilder(childArgs).start();
2271 final long start = System.nanoTime();
2272 final CountDownLatch aboutToWaitFor = new CountDownLatch(1);
2273
2274 final Thread thread = new Thread() {
2275 public void run() {
2276 try {
2277 aboutToWaitFor.countDown();
2278 Thread.currentThread().interrupt();
2279 boolean result = p.waitFor(30L * 1000L, TimeUnit.MILLISECONDS);
2280 fail("waitFor() wasn't interrupted, its return value was: " + result);
|