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

Side by Side 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 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
« no previous file with comments | « sdk/lib/async/future.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 library futures_test; 5 library futures_test;
6 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async'; 8 import 'dart:async';
9 9
10 Future testWaitEmpty() { 10 Future testWaitEmpty() {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 c2.completeError('incorrect error 1'); 69 c2.completeError('incorrect error 1');
70 70
71 return Future.wait(futures).then((_) { 71 return Future.wait(futures).then((_) {
72 throw 'incorrect error 2'; 72 throw 'incorrect error 2';
73 }).catchError((error, stackTrace) { 73 }).catchError((error, stackTrace) {
74 Expect.equals('correct error', error); 74 Expect.equals('correct error', error);
75 Expect.isNull(stackTrace); 75 Expect.isNull(stackTrace);
76 }); 76 });
77 } 77 }
78 78
79 Future testWaitWithMultipleErrorsEager() {
80 List<Future> futures = new List<Future>();
81 Completer c1 = new Completer();
82 Completer c2 = new Completer();
83 futures.add(c1.future);
84 futures.add(c2.future);
85 c1.completeError('correct error');
86 c2.completeError('incorrect error 1');
87
88 return Future.wait(futures, eagerError: true).then((_) {
89 throw 'incorrect error 2';
90 }).catchError((error, stackTrace) {
91 Expect.equals('correct error', error);
92 Expect.isNull(stackTrace);
93 });
94 }
95
79 StackTrace get currentStackTrace { 96 StackTrace get currentStackTrace {
80 try { 97 try {
81 throw 0; 98 throw 0;
82 } catch(e, st) { 99 } catch(e, st) {
83 return st; 100 return st;
84 } 101 }
85 return null; 102 return null;
86 } 103 }
87 104
88 Future testWaitWithSingleErrorWithStackTrace() { 105 Future testWaitWithSingleErrorWithStackTrace() {
(...skipping 23 matching lines...) Expand all
112 c2.completeError('incorrect error 1'); 129 c2.completeError('incorrect error 1');
113 130
114 return Future.wait(futures).then((_) { 131 return Future.wait(futures).then((_) {
115 throw 'incorrect error 2'; 132 throw 'incorrect error 2';
116 }).catchError((error, stackTrace) { 133 }).catchError((error, stackTrace) {
117 Expect.equals('correct error', error); 134 Expect.equals('correct error', error);
118 Expect.isNotNull(stackTrace); 135 Expect.isNotNull(stackTrace);
119 }); 136 });
120 } 137 }
121 138
139 Future testWaitWithMultipleErrorsWithStackTraceEager() {
140 List<Future> futures = new List<Future>();
141 Completer c1 = new Completer();
142 Completer c2 = new Completer();
143 futures.add(c1.future);
144 futures.add(c2.future);
145 c1.completeError('correct error', currentStackTrace);
146 c2.completeError('incorrect error 1');
147
148 return Future.wait(futures, eagerError: true).then((_) {
149 throw 'incorrect error 2';
150 }).catchError((error, stackTrace) {
151 Expect.equals('correct error', error);
152 Expect.isNotNull(stackTrace);
153 });
154 }
155
156 Future testEagerWait() {
157 var st;
158 try { throw 0; } catch (e, s) { st = s; }
159 Completer c1 = new Completer();
160 Completer c2 = new Completer();
161 List<Future> futures = <Future>[c1.future, c2.future];
162 Future waited = Future.wait(futures, eagerError: true);
163 var result = waited.then((v) { throw "should not be called"; },
164 onError: (e, s) {
165 Expect.equals(e, 42);
166 Expect.identical(st, s);
167 return true;
168 });
169 c1.completeError(42, st);
170 return result;
171 }
172
122 Future testForEachEmpty() { 173 Future testForEachEmpty() {
123 return Future.forEach([], (_) { 174 return Future.forEach([], (_) {
124 throw 'should not be called'; 175 throw 'should not be called';
125 }); 176 });
126 } 177 }
127 178
128 Future testForEach() { 179 Future testForEach() {
129 var seen = <int>[]; 180 var seen = <int>[];
130 return Future.forEach([1, 2, 3, 4, 5], (n) { 181 return Future.forEach([1, 2, 3, 4, 5], (n) {
131 seen.add(n); 182 seen.add(n);
(...skipping 16 matching lines...) Expand all
148 199
149 main() { 200 main() {
150 List<Future> futures = new List<Future>(); 201 List<Future> futures = new List<Future>();
151 202
152 futures.add(testWaitEmpty()); 203 futures.add(testWaitEmpty());
153 futures.add(testCompleteAfterWait()); 204 futures.add(testCompleteAfterWait());
154 futures.add(testCompleteBeforeWait()); 205 futures.add(testCompleteBeforeWait());
155 futures.add(testWaitWithMultipleValues()); 206 futures.add(testWaitWithMultipleValues());
156 futures.add(testWaitWithSingleError()); 207 futures.add(testWaitWithSingleError());
157 futures.add(testWaitWithMultipleErrors()); 208 futures.add(testWaitWithMultipleErrors());
209 futures.add(testWaitWithMultipleErrorsEager());
158 futures.add(testWaitWithSingleErrorWithStackTrace()); 210 futures.add(testWaitWithSingleErrorWithStackTrace());
159 futures.add(testWaitWithMultipleErrorsWithStackTrace()); 211 futures.add(testWaitWithMultipleErrorsWithStackTrace());
212 futures.add(testWaitWithMultipleErrorsWithStackTraceEager());
213 futures.add(testEagerWait());
160 futures.add(testForEachEmpty()); 214 futures.add(testForEachEmpty());
161 futures.add(testForEach()); 215 futures.add(testForEach());
162 futures.add(testForEachWithException()); 216 futures.add(testForEachWithException());
163 217
164 asyncStart(); 218 asyncStart();
165 Future.wait(futures).then((List list) { 219 Future.wait(futures).then((List list) {
166 Expect.equals(11, list.length); 220 Expect.equals(14, list.length);
167 asyncEnd(); 221 asyncEnd();
168 }); 222 });
169 } 223 }
OLDNEW
« 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