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

Side by Side Diff: tests/lib/async/stream_timeout_test.dart

Issue 295913003: Make Stream.where, etc., be documented as inheriting broadcast state. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Change asBroadcastStream to always only listen once to its source. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
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 import "dart:async"; 5 import "dart:async";
6 import "package:unittest/unittest.dart"; 6 import "package:unittest/unittest.dart";
7 7
8 main() { 8 main() {
9 const ms5 = const Duration(milliseconds: 5); 9 const ms5 = const Duration(milliseconds: 5);
10 const twoSecs = const Duration(seconds: 2); 10 const twoSecs = const Duration(seconds: 2);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 onError: expectAsync((e, s) { 60 onError: expectAsync((e, s) {
61 expect(ctr, 2); 61 expect(ctr, 2);
62 expect(e, new isInstanceOf<TimeoutException>()); 62 expect(e, new isInstanceOf<TimeoutException>());
63 })); 63 }));
64 c..add(42)..add(42); // No close, timeout after two events. 64 c..add(42)..add(42); // No close, timeout after two events.
65 }); 65 });
66 66
67 test("broadcast stream timeout", () { 67 test("broadcast stream timeout", () {
68 StreamController c = new StreamController.broadcast(); 68 StreamController c = new StreamController.broadcast();
69 Stream tos = c.stream.timeout(ms5); 69 Stream tos = c.stream.timeout(ms5);
70 expect(tos.isBroadcast, false); 70 expect(tos.isBroadcast, true);
71 tos.handleError(expectAsync((e, s) { 71 tos.handleError(expectAsync((e, s) {
72 expect(e, new isInstanceOf<TimeoutException>()); 72 expect(e, new isInstanceOf<TimeoutException>());
73 expect(s, null); 73 expect(s, null);
74 })).listen((v){ fail("Unexpected event"); }); 74 })).listen((v){ fail("Unexpected event"); });
75 }); 75 });
76 76
77 test("asBroadcast stream timeout", () { 77 test("asBroadcast stream timeout", () {
78 StreamController c = new StreamController.broadcast(); 78 StreamController c = new StreamController.broadcast();
79 Stream tos = c.stream.asBroadcastStream().timeout(ms5); 79 Stream tos = c.stream.asBroadcastStream().timeout(ms5);
80 expect(tos.isBroadcast, false); 80 expect(tos.isBroadcast, true);
81 tos.handleError(expectAsync((e, s) { 81 tos.handleError(expectAsync((e, s) {
82 expect(e, new isInstanceOf<TimeoutException>()); 82 expect(e, new isInstanceOf<TimeoutException>());
83 expect(s, null); 83 expect(s, null);
84 })).listen((v){ fail("Unexpected event"); }); 84 })).listen((v){ fail("Unexpected event"); });
85 }); 85 });
86 86
87 test("mapped stream timeout", () { 87 test("mapped stream timeout", () {
88 StreamController c = new StreamController(); 88 StreamController c = new StreamController();
89 Stream tos = c.stream.map((x) => 2 * x).timeout(ms5); 89 Stream tos = c.stream.map((x) => 2 * x).timeout(ms5);
90 expect(tos.isBroadcast, false); 90 expect(tos.isBroadcast, false);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 fail("Timeout not prevented by close"); 173 fail("Timeout not prevented by close");
174 }); 174 });
175 var subscription = tos.listen((_) {}, onDone: expectAsync((){})); 175 var subscription = tos.listen((_) {}, onDone: expectAsync((){}));
176 subscription.pause(); 176 subscription.pause();
177 new Timer(twoSecs, () { 177 new Timer(twoSecs, () {
178 c.close(); 178 c.close();
179 subscription.resume(); 179 subscription.resume();
180 }); 180 });
181 }); 181 });
182 } 182 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698