Chromium Code Reviews| 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 | 6 |
| 7 import 'package:stream_channel/stream_channel.dart'; | 7 import 'package:stream_channel/stream_channel.dart'; |
| 8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
| 9 | 9 |
| 10 import 'utils.dart'; | 10 import 'utils.dart'; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 sinkController.stream.listen( | 100 sinkController.stream.listen( |
| 101 expectAsync((_) {}, count: 0), | 101 expectAsync((_) {}, count: 0), |
| 102 onDone: expectAsync(() {}, count: 0)); | 102 onDone: expectAsync(() {}, count: 0)); |
| 103 await pumpEventQueue(); | 103 await pumpEventQueue(); |
| 104 }); | 104 }); |
| 105 | 105 |
| 106 test("forwards errors to the other endpoint", () { | 106 test("forwards errors to the other endpoint", () { |
| 107 channel.sink.addError("error"); | 107 channel.sink.addError("error"); |
| 108 expect(sinkController.stream.first, throwsA("error")); | 108 expect(sinkController.stream.first, throwsA("error")); |
| 109 }); | 109 }); |
| 110 | |
| 111 test("Sink.done completes once the stream is done", () { | |
| 112 channel.stream.listen(null); | |
| 113 expect(channel.sink.done, completes); | |
| 114 streamController.close(); | |
| 115 }); | |
| 116 | |
| 117 group("with allowSinkErrors: false", () { | |
| 118 setUp(() { | |
| 119 streamController = new StreamController(); | |
| 120 sinkController = new StreamController(); | |
| 121 channel = new StreamChannel.withGuarantees( | |
| 122 streamController.stream, sinkController.sink, allowSinkErrors: false); | |
| 123 }); | |
| 124 | |
| 125 test("forwards errors to Sink.done but not the stream", () { | |
| 126 channel.sink.addError("oh no"); | |
| 127 expect(channel.sink.done, throwsA("oh no")); | |
| 128 sinkController.stream.listen(null, onError: expectAsync((_) {}, count: 0)) ; | |
|
tjblasi
2016/02/04 23:16:01
line length (might just be Chromium Code Reviews U
| |
| 129 }); | |
| 130 | |
| 131 test("adding an error causes the stream to emit a done event", () { | |
| 132 expect(channel.sink.done, throwsA("oh no")); | |
| 133 | |
| 134 streamController.add(1); | |
| 135 streamController.add(2); | |
| 136 streamController.add(3); | |
| 137 | |
| 138 expect(channel.stream.listen(expectAsync((event) { | |
| 139 if (event == 2) channel.sink.addError("oh no"); | |
| 140 }, count: 2)).asFuture(), completes); | |
| 141 }); | |
| 142 | |
| 143 test("adding an error closes the inner sink", () { | |
| 144 channel.sink.addError("oh no"); | |
| 145 expect(channel.sink.done, throwsA("oh no")); | |
| 146 expect(sinkController.stream.toList(), completion(isEmpty)); | |
| 147 }); | |
| 148 }); | |
| 110 } | 149 } |
| OLD | NEW |