Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: tests/isolate/src/NestedSpawn2Test.dart

Issue 9358010: isolates in frog: playing with API improvements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/isolate/src/MixedTest.dart ('k') | tests/isolate/src/NestedSpawnTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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('TestFramework.dart'); 10 #import('TestFramework.dart');
11 11
12 class Isolate1 extends Isolate { 12 class IsolateA extends Isolate {
13 Isolate1() : super.heavy(); 13 IsolateA() : super.heavy();
14 14
15 void main() { 15 void main() {
16 this.port.receive((msg, replyTo) { 16 this.port.receive((msg, replyTo) {
17 Expect.equals("launch nested!", msg); 17 Expect.equals("launch nested!", msg);
18 new Isolate2().spawn().then((SendPort p) { 18 new IsolateB().spawn().then((SendPort p) {
19 p.send(replyTo, null); 19 p.send(replyTo, null);
20 this.port.close(); 20 this.port.close();
21 }); 21 });
22 }); 22 });
23 } 23 }
24 } 24 }
25 25
26 String msg0 = "0 there?"; 26 String msg0 = "0 there?";
27 String msg1 = "1 Yes."; 27 String msg1 = "1 Yes.";
28 String msg2 = "2 great. Think the other one is already dead?"; 28 String msg2 = "2 great. Think the other one is already dead?";
29 String msg3 = "3 Give him some time."; 29 String msg3 = "3 Give him some time.";
30 String msg4 = "4 now?"; 30 String msg4 = "4 now?";
31 String msg5 = "5 Now."; 31 String msg5 = "5 Now.";
32 String msg6 = "6 Great. Bye"; 32 String msg6 = "6 Great. Bye";
33 33
34 class Isolate2 extends Isolate { 34 class IsolateB extends Isolate {
35 Isolate2() : super.heavy(); 35 IsolateB() : super.heavy();
36 36
37 void main() { 37 void main() {
38 this.port.receive((mainPort, replyTo) { 38 this.port.receive((mainPort, replyTo) {
39 this.port.close(); 39 this.port.close();
40 // Do a little ping-pong dance to give the intermediate isolate time to 40 // Do a little ping-pong dance to give the intermediate isolate time to
41 // die. 41 // die.
42 mainPort.call(msg0).receive((msg, replyTo) { 42 mainPort.call(msg0).receive((msg, replyTo) {
43 Expect.equals("1", msg[0]); 43 Expect.equals("1", msg[0]);
44 replyTo.call(msg2).receive((msg, replyTo) { 44 replyTo.call(msg2).receive((msg, replyTo) {
45 Expect.equals("3", msg[0]); 45 Expect.equals("3", msg[0]);
46 replyTo.call(msg4).receive((msg, replyTo) { 46 replyTo.call(msg4).receive((msg, replyTo) {
47 Expect.equals("5", msg[0]); 47 Expect.equals("5", msg[0]);
48 replyTo.send(msg6, null); 48 replyTo.send(msg6, null);
49 }); 49 });
50 }); 50 });
51 }); 51 });
52 }); 52 });
53 } 53 }
54 } 54 }
55 55
56 test(TestExpectation expect) { 56 test(TestExpectation expect) {
57 expect.completes(new Isolate1().spawn()).then((SendPort port) { 57 expect.completes(new IsolateA().spawn()).then((SendPort port) {
58 port.call("launch nested!").receive(expect.runs2((msg, replyTo) { 58 port.call("launch nested!").receive(expect.runs2((msg, replyTo) {
59 Expect.equals("0", msg[0]); 59 Expect.equals("0", msg[0]);
60 replyTo.call(msg1).receive(expect.runs2((msg, replyTo) { 60 replyTo.call(msg1).receive(expect.runs2((msg, replyTo) {
61 Expect.equals("2", msg[0]); 61 Expect.equals("2", msg[0]);
62 replyTo.call(msg3).receive(expect.runs2((msg, replyTo) { 62 replyTo.call(msg3).receive(expect.runs2((msg, replyTo) {
63 Expect.equals("4", msg[0]); 63 Expect.equals("4", msg[0]);
64 replyTo.call(msg5).receive(expect.runs2((msg, replyTo) { 64 replyTo.call(msg5).receive(expect.runs2((msg, replyTo) {
65 Expect.equals("6", msg[0]); 65 Expect.equals("6", msg[0]);
66 expect.succeeded(); 66 expect.succeeded();
67 })); 67 }));
68 })); 68 }));
69 })); 69 }));
70 })); 70 }));
71 }); 71 });
72 } 72 }
73 73
74 main() { 74 main() {
75 runTests([test]); 75 runTests([test]);
76 } 76 }
OLDNEW
« no previous file with comments | « tests/isolate/src/MixedTest.dart ('k') | tests/isolate/src/NestedSpawnTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698