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

Unified Diff: test/stream_sink_completer_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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/stream_completer_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/stream_sink_completer_test.dart
diff --git a/test/stream_sink_completer_test.dart b/test/stream_sink_completer_test.dart
index 3892d2679013702aa4fc136ef4982fa766b3e464..82393fcdf71dce6b0c590c91cf72b513bb2e4d55 100644
--- a/test/stream_sink_completer_test.dart
+++ b/test/stream_sink_completer_test.dart
@@ -245,6 +245,48 @@ main() {
expect(completer.sink.close(), completes);
});
+ group("fromFuture()", () {
+ test("with a successful completion", () async {
+ var futureCompleter = new Completer();
+ var sink = StreamSinkCompleter.fromFuture(futureCompleter.future);
+ sink.add(1);
+ sink.add(2);
+ sink.add(3);
+ sink.close();
+
+ var testSink = new TestSink();
+ futureCompleter.complete(testSink);
+ await testSink.done;
+
+ expect(testSink.results[0].asValue.value, equals(1));
+ expect(testSink.results[1].asValue.value, equals(2));
+ expect(testSink.results[2].asValue.value, equals(3));
+ });
+
+ test("with an error", () async {
+ var futureCompleter = new Completer();
+ var sink = StreamSinkCompleter.fromFuture(futureCompleter.future);
+ expect(sink.done, throwsA("oh no"));
+ futureCompleter.completeError("oh no");
+ });
+ });
+
+ group("setError()", () {
+ test("produces a closed sink with the error", () {
+ completer.setError("oh no");
+ expect(completer.sink.done, throwsA("oh no"));
+ expect(completer.sink.close(), throwsA("oh no"));
+ });
+
+ test("produces an error even if done was accessed earlier", () async {
+ expect(completer.sink.done, throwsA("oh no"));
+ expect(completer.sink.close(), throwsA("oh no"));
+ await flushMicrotasks();
+
+ completer.setError("oh no");
+ });
+ });
+
test("doesn't allow the destination sink to be set multiple times", () {
completer.setDestinationSink(new TestSink());
expect(() => completer.setDestinationSink(new TestSink()),
« no previous file with comments | « test/stream_completer_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698