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

Unified Diff: tests/lib/async/stream_controller_test.dart

Issue 269283007: Make errors from StreamController onCancel calls end up in the returned future. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests. Propagate errors during cancel only to cancel future. 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 side-by-side diff with in-line comments
Download patch
Index: tests/lib/async/stream_controller_test.dart
diff --git a/tests/lib/async/stream_controller_test.dart b/tests/lib/async/stream_controller_test.dart
index f729edcd56e21030e4f49fa6a132a983bb3ddf93..d52565a56b78133f9a7d6b3fb7ef92ae106c348a 100644
--- a/tests/lib/async/stream_controller_test.dart
+++ b/tests/lib/async/stream_controller_test.dart
@@ -6,6 +6,7 @@
library stream_controller_test;
import "package:expect/expect.dart";
+import "package:async_helper/async_helper.dart";
import 'dart:async';
import 'event_helper.dart';
@@ -436,10 +437,102 @@ void testStreamEquals() {
Expect.equals(c.stream, c.stream);
}
+void testCancelThrow() {
+ asyncStart();
+ asyncStart();
+ StreamController c = new StreamController(onCancel: () {
+ asyncEnd();
+ throw "ERROR";
+ });
+ c.add(1);
+ c.add(2);
+ c.add(3);
+ Future done = c.close();
+ StreamSubscription sub;
+ sub = c.stream.listen((v) {
+ Expect.equals(1, v);
+ Future f = sub.cancel();
+ f.catchError((e) {
+ // Must complete with error from onCancel.
+ Expect.equals("ERROR", e);
+ asyncEnd();
+ });
+ });
+ done.whenComplete(asyncEnd); // Must complete without error.
floitsch 2014/05/09 15:39:21 Then add a 'catchError' first (with a 'fail'). Oth
+}
+
+void testCancelThrow2() {
+ asyncStart();
+ asyncStart();
+ asyncStart();
+ asyncStart();
+ asyncStart();
+ StreamController c2 = new StreamController(onCancel: () {
+ asyncEnd();
+ throw "ERROR";
+ });
+ c2.add(1);
+ c2.add(2);
+ Future done2 = c2.close();
+ done2.whenComplete(asyncEnd); // Should not get error;
+ StreamController c = new StreamController();
+
+ var sub;
+ sub = c.stream.listen((v) {
+ Expect.equals(1, v);
+ Future f = sub.cancel();
+ f.catchError((e) {
+ // Error from addStream stream's cancel must go only here.
+ asyncEnd();
+ Expect.equals("ERROR", e);
+ });
+ });
+ var addDone = c.addStream(c2.stream);
+ addDone.whenComplete(asyncEnd); // Should not get error.
floitsch 2014/05/09 15:39:21 ditto.
+ var done = c.done;
+ done.whenComplete(asyncEnd); // Should not get error.
+}
+
+void testCancelThrow3() {
+ asyncStart();
+ asyncStart();
+ asyncStart();
+ asyncStart();
+ asyncStart();
+ StreamController c2 = new StreamController(onCancel: () {
+ asyneEnd();
+ throw "ERROR2";
+ });
+ c2.add(1);
+ c2.add(2);
+ var done2 = c2.close();
+ StreamController c = new StreamController(onCancel: () {
+ asyncEnd();
+ throw "ERROR1";
+ });
+
+ var sub;
+ sub = c.stream.listen((v) {
+ Expect.equals(1, v);
+ Future f = sub.cancel();
+ f.catchError((e) {
+ // Only the last error ends up here.
+ Expect.equals("ERROR1", e);
+ asyncEnd();
+ });
+ });
+ var addDone = c.addStream(c2.stream);
+ addDone.whenComplete(asyncEnd); // Error must not go here.
floitsch 2014/05/09 15:39:21 ditto.
+ c.done.whenComplete(asyncEnd); // Error must not go here.
+}
+
main() {
testMultiController();
testSingleController();
testExtraMethods();
testClosed();
testStreamEquals();
+ testCancelThrow();
+ testCancelThrow2();
+ testCancelThrow3();
}
« sdk/lib/async/stream_controller.dart ('K') | « sdk/lib/async/stream_controller.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698