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

Side by Side Diff: test/null_stream_sink_test.dart

Issue 1615253002: Add ClosedStreamSink, and *Completer.setError, and StreamSinkCompleter.fromFuture. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Code review changes Created 4 years, 11 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
« no previous file with comments | « pubspec.yaml ('k') | test/stream_completer_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "dart:async";
6
7 import "package:async/async.dart";
8 import "package:test/test.dart";
9
10 import "utils.dart";
11
12 void main() {
13 group("constructors", () {
14 test("done defaults to a completed future", () {
15 var sink = new NullStreamSink();
16 expect(sink.done, completes);
17 });
18
19 test("a custom future may be passed to done", () async {
20 var completer = new Completer();
21 var sink = new NullStreamSink(done: completer.future);
22
23 var doneFired = false;
24 sink.done.then((_) {
25 doneFired = true;
26 });
27 await flushMicrotasks();
28 expect(doneFired, isFalse);
29
30 completer.complete();
31 await flushMicrotasks();
32 expect(doneFired, isTrue);
33 });
34
35 test("NullStreamSink.error passes an error to done", () {
36 var sink = new NullStreamSink.error("oh no");
37 expect(sink.done, throwsA("oh no"));
38 });
39 });
40
41 group("events", () {
42 test("are silently dropped before close", () {
43 var sink = new NullStreamSink();
44 sink.add(1);
45 sink.addError("oh no");
46 });
47
48 test("throw StateErrors after close", () {
49 var sink = new NullStreamSink();
50 expect(sink.close(), completes);
51
52 expect(() => sink.add(1), throwsStateError);
53 expect(() => sink.addError("oh no"), throwsStateError);
54 expect(() => sink.addStream(new Stream.empty()), throwsStateError);
55 });
56
57 group("addStream", () {
58 test("listens to the stream then cancels immediately", () async {
59 var sink = new NullStreamSink();
60 var canceled = false;
61 var controller = new StreamController(onCancel: () {
62 canceled = true;
63 });
64
65 expect(sink.addStream(controller.stream), completes);
66 await flushMicrotasks();
67 expect(canceled, isTrue);
68 });
69
70 test("returns the cancel future", () async {
71 var completer = new Completer();
72 var sink = new NullStreamSink();
73 var controller = new StreamController(onCancel: () => completer.future);
74
75 var addStreamFired = false;
76 sink.addStream(controller.stream).then((_) {
77 addStreamFired = true;
78 });
79 await flushMicrotasks();
80 expect(addStreamFired, isFalse);
81
82 completer.complete();
83 await flushMicrotasks();
84 expect(addStreamFired, isTrue);
85 });
86
87 test("pipes errors from the cancel future through addStream", () async {
88 var sink = new NullStreamSink();
89 var controller = new StreamController(onCancel: () => throw "oh no");
90 expect(sink.addStream(controller.stream), throwsA("oh no"));
91 });
92
93 test("causes events to throw StateErrors until the future completes",
94 () async {
95 var sink = new NullStreamSink();
96 var future = sink.addStream(new Stream.empty());
97 expect(() => sink.add(1), throwsStateError);
98 expect(() => sink.addError("oh no"), throwsStateError);
99 expect(() => sink.addStream(new Stream.empty()), throwsStateError);
100
101 await future;
102 sink.add(1);
103 sink.addError("oh no");
104 expect(sink.addStream(new Stream.empty()), completes);
105 });
106 });
107 });
108
109 test("close returns the done future", () {
110 var sink = new NullStreamSink.error("oh no");
111 expect(sink.close(), throwsA("oh no"));
112 });
113 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | test/stream_completer_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698