OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 error_group_test; | 5 library error_group_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 | 10 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 }), completion(isTrue)); | 241 }), completion(isTrue)); |
242 }); | 242 }); |
243 | 243 |
244 test('should notify the error group of a signaled exception even if the ' | 244 test('should notify the error group of a signaled exception even if the ' |
245 'stream has a listener', () { | 245 'stream has a listener', () { |
246 expect(stream.first, throwsFormatException); | 246 expect(stream.first, throwsFormatException); |
247 expect(errorGroup.done, throwsFormatException); | 247 expect(errorGroup.done, throwsFormatException); |
248 errorGroup.signalError(new FormatException()); | 248 errorGroup.signalError(new FormatException()); |
249 }); | 249 }); |
250 | 250 |
251 test("should complete .done when the stream is done even if the stream " | 251 test("should see one value and complete .done when the stream is done even " |
252 "doesn't have a listener", () { | 252 "if the stream doesn't have a listener", () { |
253 expect(errorGroup.done, completes); | 253 expect(errorGroup.done, completes); |
254 controller.add('value'); | 254 controller.add('value'); |
255 controller.close(); | 255 controller.close(); |
256 | 256 |
257 // A listener added afterwards should see an empty stream, since it's not | 257 // Now that broadcast controllers have been removed a listener should |
258 // single-subscription | 258 // see the value that has been put into the controller. |
259 expect(errorGroup.done.then((_) => stream.toList()), | 259 expect(errorGroup.done.then((_) => stream.toList()), |
260 completion(isEmpty)); | 260 completion(equals(['value']))); |
261 }); | 261 }); |
262 | 262 |
263 test("should pipe an exception from the stream to .done if the stream " | |
264 "doesn't have a listener", () { | |
265 expect(errorGroup.done, throwsFormatException); | |
266 controller.addError(new FormatException()); | |
267 | |
268 // A listener added afterwards should see an empty stream, since it's not | |
269 // single-subscription | |
270 expect(errorGroup.done.catchError((_) { | |
271 controller.add('value'); // should be ignored | |
272 return stream.toList(); | |
273 }), completion(isEmpty)); | |
274 }); | |
275 | |
276 test("should pass a signaled exception to .done if the stream doesn't " | |
277 "have a listener", | |
278 () { | |
279 expect(errorGroup.done, throwsFormatException); | |
280 errorGroup.signalError(new FormatException()); | |
281 | |
282 // A listener added afterwards should receive the exception | |
283 expect(errorGroup.done.catchError((_) { | |
284 controller.add('value'); // should be ignored | |
285 return stream.toList(); | |
286 }), completion(isEmpty)); | |
287 }); | |
288 }); | 263 }); |
289 | 264 |
290 group('with a single single-subscription stream', () { | 265 group('with a single single-subscription stream', () { |
291 StreamController controller; | 266 StreamController controller; |
292 Stream stream; | 267 Stream stream; |
293 | 268 |
294 setUp(() { | 269 setUp(() { |
295 errorGroup = new ErrorGroup(); | 270 errorGroup = new ErrorGroup(); |
296 controller = new StreamController(); | 271 controller = new StreamController(); |
297 stream = errorGroup.registerStream(controller.stream); | 272 stream = errorGroup.registerStream(controller.stream); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 expect(stream.toList(), completion(equals(['value1', 'value2']))); | 420 expect(stream.toList(), completion(equals(['value1', 'value2']))); |
446 controller..add('value1')..add('value2')..close(); | 421 controller..add('value1')..add('value2')..close(); |
447 | 422 |
448 expect(stream.toList().then((_) { | 423 expect(stream.toList().then((_) { |
449 // shouldn't cause a top-level exception | 424 // shouldn't cause a top-level exception |
450 completer.completeError(new FormatException()); | 425 completer.completeError(new FormatException()); |
451 }), completes); | 426 }), completes); |
452 }); | 427 }); |
453 }); | 428 }); |
454 } | 429 } |
OLD | NEW |