OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
7 | 7 |
8 import 'package:stream_channel/stream_channel.dart'; | 8 import 'package:stream_channel/stream_channel.dart'; |
9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
10 | 10 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 controller.addError("oh no"); | 116 controller.addError("oh no"); |
117 expect(channel.sink.done, throwsA("oh no")); | 117 expect(channel.sink.done, throwsA("oh no")); |
118 await pumpEventQueue(); | 118 await pumpEventQueue(); |
119 expect(canceled, isTrue); | 119 expect(canceled, isTrue); |
120 | 120 |
121 // Even though the sink is closed, this shouldn't throw an error because | 121 // Even though the sink is closed, this shouldn't throw an error because |
122 // the user didn't explicitly close it. | 122 // the user didn't explicitly close it. |
123 channel.sink.add(1); | 123 channel.sink.add(1); |
124 }); | 124 }); |
125 }); | 125 }); |
| 126 |
| 127 group("connect constructors", () { |
| 128 var connectPort; |
| 129 setUp(() { |
| 130 connectPort = new ReceivePort(); |
| 131 }); |
| 132 |
| 133 tearDown(() { |
| 134 connectPort.close(); |
| 135 }); |
| 136 |
| 137 test("create a connected pair of channels", () { |
| 138 var channel1 = new IsolateChannel.connectReceive(connectPort); |
| 139 var channel2 = new IsolateChannel.connectSend(connectPort.sendPort); |
| 140 |
| 141 channel1.sink.add(1); |
| 142 channel1.sink.add(2); |
| 143 channel1.sink.add(3); |
| 144 expect(channel2.stream.take(3).toList(), completion(equals([1, 2, 3]))); |
| 145 |
| 146 channel2.sink.add(4); |
| 147 channel2.sink.add(5); |
| 148 channel2.sink.add(6); |
| 149 expect(channel1.stream.take(3).toList(), completion(equals([4, 5, 6]))); |
| 150 }); |
| 151 |
| 152 test("the receiving channel produces an error if it gets the wrong message", |
| 153 () { |
| 154 var connectedChannel = new IsolateChannel.connectReceive(connectPort); |
| 155 connectPort.sendPort.send("wrong value"); |
| 156 |
| 157 expect(connectedChannel.stream.toList(), throwsStateError); |
| 158 expect(connectedChannel.sink.done, completes); |
| 159 }); |
| 160 }); |
126 } | 161 } |
OLD | NEW |