| 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 // Dart test program for testing that isolates can spawn other isolates and | 5 // Dart test program for testing that isolates can spawn other isolates and |
| 6 // that the nested isolates can communicate with the main once the spawner has | 6 // that the nested isolates can communicate with the main once the spawner has |
| 7 // disappeared. | 7 // disappeared. |
| 8 | 8 |
| 9 library NestedSpawn2Test; | 9 library NestedSpawn2Test; |
| 10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
| 11 import '../../pkg/unittest/lib/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 import "remote_unittest_helper.dart"; |
| 12 | 13 |
| 13 void isolateA(SendPort init) { | 14 void isolateA(SendPort init) { |
| 14 ReceivePort port = new ReceivePort(); | 15 ReceivePort port = new ReceivePort(); |
| 15 init.send(port.sendPort); | 16 init.send(port.sendPort); |
| 16 port.first.then((message) { | 17 port.first.then((message) { |
| 17 expect(message[0], "launch nested!"); | 18 expect(message[0], "launch nested!"); |
| 18 SendPort replyTo = message[1]; | 19 SendPort replyTo = message[1]; |
| 19 Isolate.spawn(isolateB, replyTo); | 20 Isolate.spawn(isolateB, replyTo); |
| 20 }); | 21 }); |
| 21 } | 22 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 44 _call(replyTo, msg2, ((msg, replyTo) { | 45 _call(replyTo, msg2, ((msg, replyTo) { |
| 45 expect(msg[0], "3"); | 46 expect(msg[0], "3"); |
| 46 _call(replyTo, msg4, ((msg, replyTo) { | 47 _call(replyTo, msg4, ((msg, replyTo) { |
| 47 expect(msg[0], "5"); | 48 expect(msg[0], "5"); |
| 48 replyTo.send([msg6, null]); | 49 replyTo.send([msg6, null]); |
| 49 })); | 50 })); |
| 50 })); | 51 })); |
| 51 })); | 52 })); |
| 52 } | 53 } |
| 53 | 54 |
| 54 main() { | 55 void main([args, port]) { |
| 56 if (testRemote(main, port)) return; |
| 55 test("spawned isolate can spawn other isolates", () { | 57 test("spawned isolate can spawn other isolates", () { |
| 56 ReceivePort init = new ReceivePort(); | 58 ReceivePort init = new ReceivePort(); |
| 57 Isolate.spawn(isolateA, init.sendPort); | 59 Isolate.spawn(isolateA, init.sendPort); |
| 58 init.first.then(expectAsync1((port) { | 60 init.first.then(expectAsync1((port) { |
| 59 _call(port, "launch nested!", expectAsync2((msg, replyTo) { | 61 _call(port, "launch nested!", expectAsync2((msg, replyTo) { |
| 60 expect(msg[0], "0"); | 62 expect(msg[0], "0"); |
| 61 _call(replyTo, msg1, expectAsync2((msg, replyTo) { | 63 _call(replyTo, msg1, expectAsync2((msg, replyTo) { |
| 62 expect(msg[0], "2"); | 64 expect(msg[0], "2"); |
| 63 _call(replyTo, msg3, expectAsync2((msg, replyTo) { | 65 _call(replyTo, msg3, expectAsync2((msg, replyTo) { |
| 64 expect(msg[0], "4"); | 66 expect(msg[0], "4"); |
| 65 _call(replyTo, msg5, expectAsync2((msg, _) { | 67 _call(replyTo, msg5, expectAsync2((msg, _) { |
| 66 expect(msg[0], "6"); | 68 expect(msg[0], "6"); |
| 67 })); | 69 })); |
| 68 })); | 70 })); |
| 69 })); | 71 })); |
| 70 })); | 72 })); |
| 71 })); | 73 })); |
| 72 }); | 74 }); |
| 73 } | 75 } |
| OLD | NEW |