Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: test/stream_channel_controller_test.dart

Issue 1669953002: Provide more error-handling customization. (Closed) Base URL: git@github.com:dart-lang/stream_channel.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
11 11
12 void main() { 12 void main() {
13 group("asynchronously", () { 13 group("asynchronously", () {
14 var controller; 14 var controller;
15 setUp(() { 15 setUp(() {
16 controller = new StreamChannelController(); 16 controller = new StreamChannelController();
17 }); 17 });
18 18
19 test("forwards events from the local sink to the foreign stream", () { 19 test("forwards events from the local sink to the foreign stream", () {
20 controller.local.sink..add(1)..add(2)..add(3)..close(); 20 controller.local.sink..add(1)..add(2)..add(3)..close();
21 expect(controller.foreign.stream.toList(), completion(equals([1, 2, 3]))); 21 expect(controller.foreign.stream.toList(), completion(equals([1, 2, 3])));
22 }); 22 });
23 23
24 test("forwards events from the foreign sink to the local stream", () { 24 test("forwards events from the foreign sink to the local stream", () {
25 controller.foreign.sink..add(1)..add(2)..add(3)..close(); 25 controller.foreign.sink..add(1)..add(2)..add(3)..close();
26 expect(controller.local.stream.toList(), completion(equals([1, 2, 3]))); 26 expect(controller.local.stream.toList(), completion(equals([1, 2, 3])));
27 }); 27 });
28
29 test("with allowForeignErrors: false, shuts down the connection if an "
30 "error is added to the foreign channel", () {
31 controller = new StreamChannelController(allowForeignErrors: false);
32
33 controller.foreign.sink.addError("oh no");
34 expect(controller.foreign.sink.done, throwsA("oh no"));
35 expect(controller.foreign.stream.toList(), completion(isEmpty));
36 expect(controller.local.sink.done, completes);
37 expect(controller.local.stream.toList(), completion(isEmpty));
38 });
28 }); 39 });
29 40
30 group("synchronously", () { 41 group("synchronously", () {
31 var controller; 42 var controller;
32 setUp(() { 43 setUp(() {
33 controller = new StreamChannelController(sync: true); 44 controller = new StreamChannelController(sync: true);
34 }); 45 });
35 46
36 test("synchronously forwards events from the local sink to the foreign " 47 test("synchronously forwards events from the local sink to the foreign "
37 "stream", () { 48 "stream", () {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 expect(receivedEvent, isTrue); 88 expect(receivedEvent, isTrue);
78 89
79 controller.foreign.sink.addError("oh no"); 90 controller.foreign.sink.addError("oh no");
80 expect(receivedError, isTrue); 91 expect(receivedError, isTrue);
81 92
82 controller.foreign.sink.close(); 93 controller.foreign.sink.close();
83 expect(receivedDone, isTrue); 94 expect(receivedDone, isTrue);
84 }); 95 });
85 }); 96 });
86 } 97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698