| OLD | NEW |
| 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 heavy and light isolates can be mixed. | 5 // Dart test program for testing that heavy and light isolates can be mixed. |
| 6 | 6 |
| 7 #library('MixedTest'); | 7 #library('MixedTest'); |
| 8 #import('TestFramework.dart'); | 8 #import('TestFramework.dart'); |
| 9 | 9 |
| 10 class Isolate1 extends Isolate { | 10 class IsolateA extends Isolate { |
| 11 Isolate1() : super.heavy(); | 11 IsolateA() : super.heavy(); |
| 12 | 12 |
| 13 void main() { | 13 void main() { |
| 14 this.port.receive((msg, replyTo) { | 14 this.port.receive((msg, replyTo) { |
| 15 Expect.equals("launch nested!", msg); | 15 Expect.equals("launch nested!", msg); |
| 16 new Isolate2().spawn().then((SendPort p) { | 16 new IsolateB().spawn().then((SendPort p) { |
| 17 p.call("alive?").receive((msg, ignored) { | 17 p.call("alive?").receive((msg, ignored) { |
| 18 Expect.equals("and kicking", msg); | 18 Expect.equals("and kicking", msg); |
| 19 replyTo.send(499, null); | 19 replyTo.send(499, null); |
| 20 this.port.close(); | 20 this.port.close(); |
| 21 }); | 21 }); |
| 22 }); | 22 }); |
| 23 }); | 23 }); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 class Isolate2 extends Isolate { | 27 class IsolateB extends Isolate { |
| 28 Isolate2() : super.light(); | 28 IsolateB() : super.light(); |
| 29 | 29 |
| 30 void main() { | 30 void main() { |
| 31 this.port.receive((msg, replyTo) { | 31 this.port.receive((msg, replyTo) { |
| 32 Expect.equals("alive?", msg); | 32 Expect.equals("alive?", msg); |
| 33 replyTo.send("and kicking", null); | 33 replyTo.send("and kicking", null); |
| 34 this.port.close(); | 34 this.port.close(); |
| 35 }); | 35 }); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 test(TestExpectation expect) { | 39 test(TestExpectation expect) { |
| 40 expect.completes(new Isolate1().spawn()).then((SendPort port) { | 40 expect.completes(new IsolateA().spawn()).then((SendPort port) { |
| 41 port.call("launch nested!").receive(expect.runs2((msg, ignored) { | 41 port.call("launch nested!").receive(expect.runs2((msg, ignored) { |
| 42 Expect.equals(499, msg); | 42 Expect.equals(499, msg); |
| 43 expect.succeeded(); | 43 expect.succeeded(); |
| 44 })); | 44 })); |
| 45 }); | 45 }); |
| 46 } | 46 } |
| 47 | 47 |
| 48 main() { | 48 main() { |
| 49 runTests([test]); | 49 runTests([test]); |
| 50 } | 50 } |
| OLD | NEW |