| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 import "dart:io"; | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 import "package:async_helper/async_helper.dart"; | |
| 9 | |
| 10 void testSignals(int usr1Expect, | |
| 11 int usr2Expect, | |
| 12 [int usr1Send, | |
| 13 int usr2Send, | |
| 14 bool shouldFail = false]) { | |
| 15 if (usr1Send == null) usr1Send = usr1Expect; | |
| 16 if (usr2Send == null) usr2Send = usr2Expect; | |
| 17 asyncStart(); | |
| 18 Process.start(Platform.executable, | |
| 19 [Platform.script.resolve('signals_test_script.dart').toFilePath(), | |
| 20 usr1Expect.toString(), | |
| 21 usr2Expect.toString()]) | |
| 22 .then((process) { | |
| 23 process.stdin.close(); | |
| 24 process.stderr.drain(); | |
| 25 int v = 0; | |
| 26 process.stdout.listen((out) { | |
| 27 // Send as many signals as 'ready\n' received on stdout | |
| 28 int count = out.where((c) => c == '\n'.codeUnitAt(0)).length; | |
| 29 for (int i = 0; i < count; i++) { | |
| 30 if (v < usr1Send) { | |
| 31 process.kill(ProcessSignal.SIGUSR1); | |
| 32 } else if (v < usr1Send + usr2Send) { | |
| 33 process.kill(ProcessSignal.SIGUSR2); | |
| 34 } | |
| 35 v++; | |
| 36 } | |
| 37 }); | |
| 38 process.exitCode.then((exitCode) { | |
| 39 Expect.equals(shouldFail, exitCode != 0); | |
| 40 asyncEnd(); | |
| 41 }); | |
| 42 }); | |
| 43 } | |
| 44 | |
| 45 | |
| 46 void testListenCancel() { | |
| 47 for (int i = 0; i < 10; i++) { | |
| 48 ProcessSignal.SIGUSR1.watch().listen(null).cancel(); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 void main() { | |
| 53 testListenCancel(); | |
| 54 if (Platform.isWindows) return; | |
| 55 testSignals(0, 0); | |
| 56 testSignals(1, 0); | |
| 57 testSignals(0, 1); | |
| 58 testSignals(1, 1); | |
| 59 testSignals(10, 10); | |
| 60 testSignals(10, 1); | |
| 61 testSignals(1, 10); | |
| 62 testSignals(1, 0, 0, 1, true); | |
| 63 testSignals(0, 1, 1, 0, true); | |
| 64 } | |
| OLD | NEW |