| 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 CountTest; | 5 library CountTest; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 import "remote_unittest_helper.dart"; | 8 import "remote_unittest_helper.dart"; |
| 9 | 9 |
| 10 void countMessages(replyTo) { | 10 void countMessages(replyTo) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 }); | 24 }); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void main([args, port]) { | 27 void main([args, port]) { |
| 28 if (testRemote(main, port)) return; | 28 if (testRemote(main, port)) return; |
| 29 test("count 10 consecutive messages", () { | 29 test("count 10 consecutive messages", () { |
| 30 ReceivePort local = new ReceivePort(); | 30 ReceivePort local = new ReceivePort(); |
| 31 Isolate.spawn(countMessages, local.sendPort); | 31 Isolate.spawn(countMessages, local.sendPort); |
| 32 SendPort remote; | 32 SendPort remote; |
| 33 int count = 0; | 33 int count = 0; |
| 34 var done = expectAsync0((){}); | 34 var done = expectAsync((){}); |
| 35 local.listen((msg) { | 35 local.listen((msg) { |
| 36 switch (msg[0]) { | 36 switch (msg[0]) { |
| 37 case "init": | 37 case "init": |
| 38 expect(remote, null); | 38 expect(remote, null); |
| 39 remote = msg[1]; | 39 remote = msg[1]; |
| 40 remote.send(++count); | 40 remote.send(++count); |
| 41 break; | 41 break; |
| 42 case "count": | 42 case "count": |
| 43 expect(msg[1], count * 2); | 43 expect(msg[1], count * 2); |
| 44 if (count == 10) { | 44 if (count == 10) { |
| 45 remote.send(-1); | 45 remote.send(-1); |
| 46 } else { | 46 } else { |
| 47 remote.send(++count); | 47 remote.send(++count); |
| 48 } | 48 } |
| 49 break; | 49 break; |
| 50 case "done": | 50 case "done": |
| 51 expect(count, 10); | 51 expect(count, 10); |
| 52 local.close(); | 52 local.close(); |
| 53 done(); | 53 done(); |
| 54 break; | 54 break; |
| 55 default: | 55 default: |
| 56 fail("unreachable: ${msg[0]}"); | 56 fail("unreachable: ${msg[0]}"); |
| 57 } | 57 } |
| 58 }); | 58 }); |
| 59 }); | 59 }); |
| 60 } | 60 } |
| OLD | NEW |