| 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/unittest/lib/unittest.dart'; |
| 11 | 11 |
| 12 expectResponse() { | 12 expectResponse() { |
| 13 port.receive(expectAsync2((msg, r) { | 13 var receivePort = new ReceivePort(); |
| 14 receivePort.receive(expectAsync2((msg, r) { |
| 14 expect('isolate', msg); | 15 expect('isolate', msg); |
| 15 expect('main', shared.output); | 16 expect('main', shared.output); |
| 16 port.close(); | 17 receivePort.close(); |
| 17 })); | 18 })); |
| 19 return receivePort; |
| 18 } | 20 } |
| 19 | 21 |
| 20 void main() { | 22 void main() { |
| 21 test("package in spawnFunction()", () { | 23 test("package in spawnFunction()", () { |
| 22 expectResponse(); | 24 var replyPort = expectResponse().toSendPort(); |
| 23 shared.output = 'main'; | 25 shared.output = 'main'; |
| 24 var sendPort = spawnFunction(isolate_main); | 26 var sendPort = spawnFunction(isolate_main); |
| 25 sendPort.send("sendPort", port.toSendPort()); | 27 sendPort.send("sendPort", replyPort); |
| 26 }); | 28 }); |
| 27 | 29 |
| 28 test("package in spawnUri() of sibling file", () { | 30 test("package in spawnUri() of sibling file", () { |
| 29 expectResponse(); | 31 var replyPort = expectResponse().toSendPort(); |
| 30 shared.output = 'main'; | 32 shared.output = 'main'; |
| 31 var sendPort = spawnUri('sibling_isolate.dart'); | 33 var sendPort = spawnUri('sibling_isolate.dart'); |
| 32 sendPort.send('sendPort', port.toSendPort()); | 34 sendPort.send('sendPort', replyPort); |
| 33 }); | 35 }); |
| 34 | 36 |
| 35 test("package in spawnUri() of file in folder", () { | 37 test("package in spawnUri() of file in folder", () { |
| 36 expectResponse(); | 38 var replyPort = expectResponse().toSendPort(); |
| 37 shared.output = 'main'; | 39 shared.output = 'main'; |
| 38 var sendPort = spawnUri('test_folder/folder_isolate.dart'); | 40 var sendPort = spawnUri('test_folder/folder_isolate.dart'); |
| 39 sendPort.send('sendPort', port.toSendPort()); | 41 sendPort.send('sendPort', replyPort); |
| 40 }); | 42 }); |
| 41 } | 43 } |
| 42 | 44 |
| 43 void isolate_main() { | 45 void isolate_main() { |
| 44 shared.output = 'isolate'; | 46 shared.output = 'isolate'; |
| 45 port.receive((msg, replyTo) { | 47 port.receive((msg, replyTo) { |
| 46 replyTo.send(shared.output); | 48 replyTo.send(shared.output); |
| 47 }); | 49 }); |
| 48 } | 50 } |
| OLD | NEW |