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

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

Issue 68523005: Make Future.wait have an eagerError option that defaults to false. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 1 month 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 | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/futures_test.dart
diff --git a/tests/lib/async/futures_test.dart b/tests/lib/async/futures_test.dart
index 9b7f00a4914a16c5ca9fed3c7f75a4be0e16191d..21121206d4469e4297f68fd4d81b19d554f89b2f 100644
--- a/tests/lib/async/futures_test.dart
+++ b/tests/lib/async/futures_test.dart
@@ -76,6 +76,23 @@ Future testWaitWithMultipleErrors() {
});
}
+Future testWaitWithMultipleErrorsEager() {
+ List<Future> futures = new List<Future>();
+ Completer c1 = new Completer();
+ Completer c2 = new Completer();
+ futures.add(c1.future);
+ futures.add(c2.future);
+ c1.completeError('correct error');
+ c2.completeError('incorrect error 1');
+
+ return Future.wait(futures, eagerError: true).then((_) {
+ throw 'incorrect error 2';
+ }).catchError((error, stackTrace) {
+ Expect.equals('correct error', error);
+ Expect.isNull(stackTrace);
+ });
+}
+
StackTrace get currentStackTrace {
try {
throw 0;
@@ -119,6 +136,40 @@ Future testWaitWithMultipleErrorsWithStackTrace() {
});
}
+Future testWaitWithMultipleErrorsWithStackTraceEager() {
+ List<Future> futures = new List<Future>();
+ Completer c1 = new Completer();
+ Completer c2 = new Completer();
+ futures.add(c1.future);
+ futures.add(c2.future);
+ c1.completeError('correct error', currentStackTrace);
+ c2.completeError('incorrect error 1');
+
+ return Future.wait(futures, eagerError: true).then((_) {
+ throw 'incorrect error 2';
+ }).catchError((error, stackTrace) {
+ Expect.equals('correct error', error);
+ Expect.isNotNull(stackTrace);
+ });
+}
+
+Future testEagerWait() {
+ var st;
+ try { throw 0; } catch (e, s) { st = s; }
+ Completer c1 = new Completer();
+ Completer c2 = new Completer();
+ List<Future> futures = <Future>[c1.future, c2.future];
+ Future waited = Future.wait(futures, eagerError: true);
+ var result = waited.then((v) { throw "should not be called"; },
+ onError: (e, s) {
+ Expect.equals(e, 42);
+ Expect.identical(st, s);
+ return true;
+ });
+ c1.completeError(42, st);
+ return result;
+}
+
Future testForEachEmpty() {
return Future.forEach([], (_) {
throw 'should not be called';
@@ -155,15 +206,18 @@ main() {
futures.add(testWaitWithMultipleValues());
futures.add(testWaitWithSingleError());
futures.add(testWaitWithMultipleErrors());
+ futures.add(testWaitWithMultipleErrorsEager());
futures.add(testWaitWithSingleErrorWithStackTrace());
futures.add(testWaitWithMultipleErrorsWithStackTrace());
+ futures.add(testWaitWithMultipleErrorsWithStackTraceEager());
+ futures.add(testEagerWait());
futures.add(testForEachEmpty());
futures.add(testForEach());
futures.add(testForEachWithException());
asyncStart();
Future.wait(futures).then((List list) {
- Expect.equals(11, list.length);
+ Expect.equals(14, list.length);
asyncEnd();
});
}
« no previous file with comments | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698