OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library CountTest; | |
6 import '../../pkg/unittest/lib/unittest.dart'; | |
7 import 'dart:isolate'; | |
8 | |
9 void countMessages() { | |
10 int count = 0; | |
11 IsolateSink replySink; | |
12 bool isFirst = true; | |
13 stream.listen((msg) { | |
14 if (isFirst) { | |
15 replySink = msg; | |
16 isFirst = false; | |
17 return; | |
18 } | |
19 replySink.add(count); | |
20 count++; | |
21 }, onDone: () { | |
22 expect(count, 10); | |
23 replySink.close(); | |
24 }); | |
25 } | |
26 | |
27 void main() { | |
28 test("count 10 consecutive stream messages", () { | |
29 int count = 0; | |
30 MessageBox box = new MessageBox(); | |
31 IsolateSink remote = streamSpawnFunction(countMessages); | |
32 remote.add(box.sink); | |
33 box.stream.listen(expectAsync1((remoteCount) { | |
34 expect(remoteCount, count); | |
35 count++; | |
36 if (count < 10) { | |
37 remote.add(null); | |
38 } else { | |
39 remote.close(); | |
40 } | |
41 }, count: 10), onDone: expectAsync0(() { | |
42 expect(count, 10); | |
43 })); | |
44 remote.add(null); | |
45 }); | |
46 } | |
OLD | NEW |