OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 // | 4 // |
5 // Process test program to test process communication. | 5 // Process test program to test process communication. |
6 | 6 |
7 library ProcessKillTest; | 7 library ProcessKillTest; |
| 8 |
| 9 import 'dart:io'; |
| 10 |
| 11 import "package:async_helper/async_helper.dart"; |
8 import "package:expect/expect.dart"; | 12 import "package:expect/expect.dart"; |
9 import "dart:io"; | 13 |
10 import "process_test_util.dart"; | 14 import "process_test_util.dart"; |
11 | 15 |
12 testKill() { | 16 testKill() { |
| 17 asyncStart(); |
13 // Start a process that will hang waiting for input until killed. | 18 // Start a process that will hang waiting for input until killed. |
14 Process.start(getProcessTestFileName(), const ["0", "1", "0", "0"]).then((p) { | 19 Process.start(getProcessTestFileName(), const ["0", "1", "0", "0"]).then((p) { |
15 p.exitCode.then((exitCode) { | 20 p.exitCode.then((exitCode) { |
16 // Process killed from the side so exit code is not 0. | 21 // Process killed from the side so exit code is not 0. |
17 Expect.isTrue(exitCode != 0); | 22 Expect.isTrue(exitCode != 0); |
18 // Killing a process that is already dead returns false. | 23 // Killing a process that is already dead returns false. |
19 Expect.isFalse(p.kill()); | 24 Expect.isFalse(p.kill()); |
| 25 asyncEnd(); |
20 }); | 26 }); |
21 Expect.isTrue(p.kill()); | 27 Expect.isTrue(p.kill()); |
22 }); | 28 }); |
23 } | 29 } |
24 | 30 |
| 31 testKillPid() { |
| 32 asyncStart(); |
| 33 // Start a process that will hang waiting for input until killed. |
| 34 Process.start(getProcessTestFileName(), const ["0", "1", "0", "0"]).then((p) { |
| 35 p.exitCode.then((exitCode) { |
| 36 // Process killed from the side so exit code is not 0. |
| 37 Expect.isTrue(exitCode != 0); |
| 38 // Killing a process that is already dead returns false. |
| 39 Expect.isFalse(Process.killPid(p.pid)); |
| 40 asyncEnd(); |
| 41 }); |
| 42 Expect.isTrue(Process.killPid(p.pid)); |
| 43 }); |
| 44 } |
| 45 |
25 main() { | 46 main() { |
26 testKill(); | 47 testKill(); |
| 48 testKillPid(); |
27 } | 49 } |
OLD | NEW |