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 // PackageRoot=packages/ | 5 // PackageRoot=packages/ |
6 | 6 |
7 library package_isolate_test; | 7 library package_isolate_test; |
8 import 'package:shared.dart' as shared; | 8 import 'package:shared.dart' as shared; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 import '../../../pkg/unittest/lib/unittest.dart'; | 10 import '../../../pkg/async_helper/lib/async_helper.dart'; |
| 11 import '../../../pkg/expect/lib/expect.dart'; |
11 | 12 |
12 expectResponse() { | 13 expectResponse() { |
| 14 asyncStart(); |
13 var receivePort = new ReceivePort(); | 15 var receivePort = new ReceivePort(); |
14 receivePort.receive(expectAsync2((msg, r) { | 16 receivePort.first.then((msg) { |
15 expect('isolate', msg); | 17 Expect.equals('isolate', msg); |
16 expect('main', shared.output); | 18 Expect.equals('main', shared.output); |
17 receivePort.close(); | 19 asyncEnd(); |
18 })); | 20 }); |
19 return receivePort; | 21 return receivePort; |
20 } | 22 } |
21 | 23 |
22 void main() { | 24 void main() { |
23 test("package in spawnFunction()", () { | 25 { |
24 var replyPort = expectResponse().toSendPort(); | 26 var replyPort = expectResponse().sendPort; |
25 shared.output = 'main'; | 27 shared.output = 'main'; |
26 var sendPort = spawnFunction(isolate_main); | 28 Isolate.spawn(isolate_main, replyPort); |
27 sendPort.send("sendPort", replyPort); | 29 } |
28 }); | 30 |
29 | 31 { |
30 test("package in spawnUri() of sibling file", () { | 32 // Package in spawnUri() of sibling file. |
31 var replyPort = expectResponse().toSendPort(); | 33 var replyPort = expectResponse().sendPort; |
32 shared.output = 'main'; | 34 shared.output = 'main'; |
33 var sendPort = spawnUri('sibling_isolate.dart'); | 35 Isolate.spawnUri(Uri.parse('sibling_isolate.dart'), [], replyPort); |
34 sendPort.send('sendPort', replyPort); | 36 } |
35 }); | |
36 | 37 |
37 test("package in spawnUri() of file in folder", () { | 38 { |
38 var replyPort = expectResponse().toSendPort(); | 39 // Package in spawnUri() of file in folder. |
| 40 var replyPort = expectResponse().sendPort; |
39 shared.output = 'main'; | 41 shared.output = 'main'; |
40 var sendPort = spawnUri('test_folder/folder_isolate.dart'); | 42 Isolate.spawnUri(Uri.parse('test_folder/folder_isolate.dart'), |
41 sendPort.send('sendPort', replyPort); | 43 [], replyPort); |
42 }); | 44 } |
43 } | 45 } |
44 | 46 |
45 void isolate_main() { | 47 void isolate_main(SendPort replyTo) { |
46 shared.output = 'isolate'; | 48 shared.output = 'isolate'; |
47 port.receive((msg, replyTo) { | 49 replyTo.send(shared.output); |
48 replyTo.send(shared.output); | |
49 }); | |
50 } | 50 } |
OLD | NEW |