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 library RequestReplyTest; | 5 library RequestReplyTest; |
6 | 6 |
7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import "remote_unittest_helper.dart"; | 9 import "remote_unittest_helper.dart"; |
10 | 10 |
11 void entry(initPort) { | 11 void entry(initPort) { |
12 ReceivePort port = new ReceivePort(); | 12 ReceivePort port = new ReceivePort(); |
13 initPort.send(port.sendPort); | 13 initPort.send(port.sendPort); |
14 port.listen((pair) { | 14 port.listen((pair) { |
15 var message = pair[0]; | 15 var message = pair[0]; |
16 SendPort replyTo = pair[1]; | 16 SendPort replyTo = pair[1]; |
17 replyTo.send(message + 87); | 17 replyTo.send(message + 87); |
18 port.close(); | 18 port.close(); |
19 }); | 19 }); |
20 } | 20 } |
21 | 21 |
22 void main([args, port]) { | 22 void main([args, port]) { |
23 if (testRemote(main, port)) return; | 23 if (testRemote(main, port)) return; |
24 test("send", () { | 24 test("send", () { |
25 ReceivePort init = new ReceivePort(); | 25 ReceivePort init = new ReceivePort(); |
26 Isolate.spawn(entry, init.sendPort); | 26 Isolate.spawn(entry, init.sendPort); |
27 init.first.then(expectAsync1((port) { | 27 init.first.then(expectAsync((port) { |
28 ReceivePort reply = new ReceivePort(); | 28 ReceivePort reply = new ReceivePort(); |
29 port.send([99, reply.sendPort]); | 29 port.send([99, reply.sendPort]); |
30 reply.listen(expectAsync1((message) { | 30 reply.listen(expectAsync((message) { |
31 expect(message, 99 + 87); | 31 expect(message, 99 + 87); |
32 reply.close(); | 32 reply.close(); |
33 })); | 33 })); |
34 })); | 34 })); |
35 }); | 35 }); |
36 } | 36 } |
OLD | NEW |