OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Regression test case for http://dartbug.com/23244 | 5 // Regression test case for http://dartbug.com/23244 |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 import 'package:async_helper/async_helper.dart'; |
8 | 9 |
9 enum Fisk { | 10 enum Fisk { |
10 torsk, | 11 torsk, |
11 } | 12 } |
12 | 13 |
13 isolate1(SendPort port) { | 14 isolate1(SendPort port) { |
14 port.send(Fisk.torsk); | 15 port.send(Fisk.torsk); |
15 } | 16 } |
16 | 17 |
17 isolate2(SendPort port) { | 18 isolate2(SendPort port) { |
18 port.send([Fisk.torsk]); | 19 port.send([Fisk.torsk]); |
19 } | 20 } |
20 | 21 |
21 isolate3(SendPort port) { | 22 isolate3(SendPort port) { |
22 var x = new Map<int, Fisk>(); | 23 var x = new Map<int, Fisk>(); |
23 x[0] = Fisk.torsk; | 24 x[0] = Fisk.torsk; |
24 x[1] = Fisk.torsk; | 25 x[1] = Fisk.torsk; |
25 port.send(x); | 26 port.send(x); |
26 } | 27 } |
27 | 28 |
28 main() async { | 29 main() async { |
29 var port = new ReceivePort(); | 30 var port = new ReceivePort(); |
| 31 asyncStart(); |
30 await Isolate.spawn(isolate1, port.sendPort); | 32 await Isolate.spawn(isolate1, port.sendPort); |
31 Completer completer1 = new Completer(); | 33 Completer completer1 = new Completer(); |
32 port.listen((message) { | 34 port.listen((message) { |
33 print("Received $message"); | 35 print("Received $message"); |
34 port.close(); | 36 port.close(); |
35 expectTorsk(message); | 37 expectTorsk(message); |
36 completer1.complete(); | 38 completer1.complete(); |
37 }); | 39 }); |
38 await completer1.future; | 40 await completer1.future; |
39 Completer completer2 = new Completer(); | 41 Completer completer2 = new Completer(); |
40 port = new ReceivePort(); | 42 port = new ReceivePort(); |
41 await Isolate.spawn(isolate2, port.sendPort); | 43 await Isolate.spawn(isolate2, port.sendPort); |
42 port.listen((message) { | 44 port.listen((message) { |
43 print("Received $message"); | 45 print("Received $message"); |
44 port.close(); | 46 port.close(); |
45 expectTorsk(message[0]); | 47 expectTorsk(message[0]); |
46 completer2.complete(); | 48 completer2.complete(); |
47 }); | 49 }); |
48 await completer2.future; | 50 await completer2.future; |
49 port = new ReceivePort(); | 51 port = new ReceivePort(); |
50 await Isolate.spawn(isolate3, port.sendPort); | 52 await Isolate.spawn(isolate3, port.sendPort); |
51 port.listen((message) { | 53 port.listen((message) { |
52 print("Received $message"); | 54 print("Received $message"); |
53 port.close(); | 55 port.close(); |
54 expectTorsk(message[0]); | 56 expectTorsk(message[0]); |
55 expectTorsk(message[1]); | 57 expectTorsk(message[1]); |
| 58 asyncEnd(); |
56 }); | 59 }); |
57 } | 60 } |
58 | 61 |
59 expectTorsk(Fisk fisk) { | 62 expectTorsk(Fisk fisk) { |
60 if (fisk != Fisk.torsk) { | 63 if (fisk != Fisk.torsk) { |
61 throw "$fisk isn't a ${Fisk.torsk}"; | 64 throw "$fisk isn't a ${Fisk.torsk}"; |
62 } | 65 } |
63 } | 66 } |
64 | |
OLD | NEW |