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

Side by Side Diff: pkg/scheduled_test/test/scheduled_test_test.dart

Issue 12224128: Pump the event queue manually rather than using a timer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Get rid of one more sleep call Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « pkg/scheduled_test/test/metatest.dart ('k') | pkg/scheduled_test/test/utils.dart » ('j') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 scheduled_test_test; 5 library scheduled_test_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:scheduled_test/scheduled_test.dart'; 9 import 'package:scheduled_test/scheduled_test.dart';
10 import 'package:scheduled_test/src/utils.dart'; 10
11 import 'metatest.dart'; 11 import 'metatest.dart';
12 import 'utils.dart';
12 13
13 void main() { 14 void main() {
14 expectTestsPass('a scheduled test with a correct synchronous expectation ' 15 expectTestsPass('a scheduled test with a correct synchronous expectation '
15 'should pass', () { 16 'should pass', () {
16 test('test', () { 17 test('test', () {
17 expect('foo', equals('foo')); 18 expect('foo', equals('foo'));
18 }); 19 });
19 }); 20 });
20 21
21 expectTestsFail('a scheduled test with an incorrect synchronous expectation ' 22 expectTestsFail('a scheduled test with an incorrect synchronous expectation '
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 test('asynchronous value', () { 89 test('asynchronous value', () {
89 var future = schedule(() => new Future.immediate('value')); 90 var future = schedule(() => new Future.immediate('value'));
90 expect(future, completion(equals('value'))); 91 expect(future, completion(equals('value')));
91 }); 92 });
92 }); 93 });
93 94
94 expectTestsPass('scheduled blocks should wait for their Future return values ' 95 expectTestsPass('scheduled blocks should wait for their Future return values '
95 'to complete before proceeding', () { 96 'to complete before proceeding', () {
96 test('test', () { 97 test('test', () {
97 var value = 'unset'; 98 var value = 'unset';
98 schedule(() => sleep(50).then((_) { 99 schedule(() => pumpEventQueue().then((_) {
99 value = 'set'; 100 value = 'set';
100 })); 101 }));
101 schedule(() => expect(value, equals('set'))); 102 schedule(() => expect(value, equals('set')));
102 }); 103 });
103 }); 104 });
104 105
105 expectTestsFail('a test failure in a chained future in a scheduled block ' 106 expectTestsFail('a test failure in a chained future in a scheduled block '
106 'should be registered', () { 107 'should be registered', () {
107 test('test', () { 108 test('test', () {
108 schedule(() => new Future.immediate('foo') 109 schedule(() => new Future.immediate('foo')
109 .then((v) => expect(v, equals('bar')))); 110 .then((v) => expect(v, equals('bar'))));
110 }); 111 });
111 }); 112 });
112 113
113 expectTestsFail('an error in a chained future in a scheduled block should be ' 114 expectTestsFail('an error in a chained future in a scheduled block should be '
114 'registered', () { 115 'registered', () {
115 test('test', () { 116 test('test', () {
116 schedule(() => new Future.immediate(null).then((_) { 117 schedule(() => new Future.immediate(null).then((_) {
117 throw 'error'; 118 throw 'error';
118 })); 119 }));
119 }); 120 });
120 }); 121 });
121 122
122 expectTestsFail('an out-of-band failure in wrapAsync is handled', () { 123 expectTestsFail('an out-of-band failure in wrapAsync is handled', () {
123 test('test', () { 124 test('test', () {
125 var waiter = new Waiter();
124 schedule(() { 126 schedule(() {
125 sleep(10).then(wrapAsync((_) => expect('foo', equals('bar')))); 127 waiter.wait(1).then(wrapAsync((_) => expect('foo', equals('bar'))));
126 }); 128 });
127 schedule(() => sleep(50)); 129 schedule(() => waiter.wait(2));
128 }); 130 });
129 }); 131 });
130 132
131 expectTestsFail('an out-of-band failure in wrapAsync that finishes after the ' 133 expectTestsFail('an out-of-band failure in wrapAsync that finishes after the '
132 'schedule is handled', () { 134 'schedule is handled', () {
133 test('test', () { 135 test('test', () {
136 var waiter = new Waiter();
134 schedule(() { 137 schedule(() {
135 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar')))); 138 waiter.wait(2).then(wrapAsync((_) => expect('foo', equals('bar'))));
136 }); 139 });
137 schedule(() => sleep(10)); 140 schedule(() => waiter.wait(1));
138 }); 141 });
139 }); 142 });
140 143
141 expectTestsFail('an out-of-band error reported via signalError is ' 144 expectTestsFail('an out-of-band error reported via signalError is '
142 'handled', () { 145 'handled', () {
143 test('test', () { 146 test('test', () {
147 var waiter = new Waiter();
144 schedule(() { 148 schedule(() {
145 sleep(10).then((_) => currentSchedule.signalError('bad')); 149 waiter.wait(1).then((_) => currentSchedule.signalError('bad'));
146 }); 150 });
147 schedule(() => sleep(50)); 151 schedule(() => waiter.wait(2));
148 }); 152 });
149 }); 153 });
150 154
151 expectTestsFail('an out-of-band error reported via signalError that finished ' 155 expectTestsFail('an out-of-band error reported via signalError that finished '
152 'after the schedule is handled', () { 156 'after the schedule is handled', () {
153 test('test', () { 157 test('test', () {
158 var waiter = new Waiter();
154 schedule(() { 159 schedule(() {
155 var done = wrapAsync((_) {}); 160 var done = wrapAsync((_) {});
156 sleep(50).then((_) { 161 waiter.wait(2).then((_) {
157 currentSchedule.signalError('bad'); 162 currentSchedule.signalError('bad');
158 done(null); 163 done(null);
159 }); 164 });
160 }); 165 });
161 schedule(() => sleep(10)); 166 schedule(() => waiter.wait(1));
162 }); 167 });
163 }); 168 });
164 169
165 expectTestsFail('a synchronous error reported via signalError is handled', () { 170 expectTestsFail('a synchronous error reported via signalError is handled', () {
166 test('test', () { 171 test('test', () {
167 currentSchedule.signalError('bad'); 172 currentSchedule.signalError('bad');
168 }); 173 });
169 }); 174 });
170 175
171 expectTestsPass('the onComplete queue is run if a test is successful', () { 176 expectTestsPass('the onComplete queue is run if a test is successful', () {
(...skipping 12 matching lines...) Expand all
184 }); 189 });
185 190
186 expectTestsPass('the onComplete queue is run after an out-of-band callback', 191 expectTestsPass('the onComplete queue is run after an out-of-band callback',
187 () { 192 () {
188 var outOfBandRun = false; 193 var outOfBandRun = false;
189 test('test1', () { 194 test('test1', () {
190 currentSchedule.onComplete.schedule(() { 195 currentSchedule.onComplete.schedule(() {
191 expect(outOfBandRun, isTrue); 196 expect(outOfBandRun, isTrue);
192 }); 197 });
193 198
194 sleep(50).then(wrapAsync((_) { 199 pumpEventQueue().then(wrapAsync((_) {
195 outOfBandRun = true; 200 outOfBandRun = true;
196 })); 201 }));
197 }); 202 });
198 }); 203 });
199 204
200 expectTestsPass('the onComplete queue is run after an out-of-band callback ' 205 expectTestsPass('the onComplete queue is run after an out-of-band callback '
201 'and waits for another out-of-band callback', () { 206 'and waits for another out-of-band callback', () {
202 var outOfBand1Run = false; 207 var outOfBand1Run = false;
203 var outOfBand2Run = false; 208 var outOfBand2Run = false;
204 test('test1', () { 209 test('test1', () {
205 currentSchedule.onComplete.schedule(() { 210 currentSchedule.onComplete.schedule(() {
206 expect(outOfBand1Run, isTrue); 211 expect(outOfBand1Run, isTrue);
207 212
208 sleep(50).then(wrapAsync((_) { 213 pumpEventQueue().then(wrapAsync((_) {
209 outOfBand2Run = true; 214 outOfBand2Run = true;
210 })); 215 }));
211 }); 216 });
212 217
213 sleep(50).then(wrapAsync((_) { 218 pumpEventQueue().then(wrapAsync((_) {
214 outOfBand1Run = true; 219 outOfBand1Run = true;
215 })); 220 }));
216 }); 221 });
217 222
218 test('test2', () => expect(outOfBand2Run, isTrue)); 223 test('test2', () => expect(outOfBand2Run, isTrue));
219 }); 224 });
220 225
221 expectTestsFail('an out-of-band callback in the onComplete queue blocks the ' 226 expectTestsFail('an out-of-band callback in the onComplete queue blocks the '
222 'test', () { 227 'test', () {
223 var outOfBandRun = false;
224 test('test', () { 228 test('test', () {
225 currentSchedule.onComplete.schedule(() { 229 currentSchedule.onComplete.schedule(() {
226 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar')))); 230 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar'))));
227 }); 231 });
228 }); 232 });
229 }); 233 });
230 234
231 expectTestsPass('an out-of-band callback blocks onComplete even with an ' 235 expectTestsPass('an out-of-band callback blocks onComplete even with an '
232 'unrelated error', () { 236 'unrelated error', () {
233 var outOfBandRun = false; 237 var outOfBandRun = false;
234 var outOfBandSetInOnComplete = false; 238 var outOfBandSetInOnComplete = false;
235 test('test 1', () { 239 test('test 1', () {
236 currentSchedule.onComplete.schedule(() { 240 currentSchedule.onComplete.schedule(() {
237 outOfBandSetInOnComplete = outOfBandRun; 241 outOfBandSetInOnComplete = outOfBandRun;
238 }); 242 });
239 243
240 sleep(50).then(wrapAsync((_) { 244 pumpEventQueue().then(wrapAsync((_) {
241 outOfBandRun = true; 245 outOfBandRun = true;
242 })); 246 }));
243 247
244 schedule(() => expect('foo', equals('bar'))); 248 schedule(() => expect('foo', equals('bar')));
245 }); 249 });
246 250
247 test('test 2', () => expect(outOfBandSetInOnComplete, isTrue)); 251 test('test 2', () => expect(outOfBandSetInOnComplete, isTrue));
248 }, passing: ['test 2']); 252 }, passing: ['test 2']);
249 253
250 expectTestsPass('the onComplete queue is run after an asynchronous error', 254 expectTestsPass('the onComplete queue is run after an asynchronous error',
(...skipping 27 matching lines...) Expand all
278 }); 282 });
279 }, passing: ['test 2']); 283 }, passing: ['test 2']);
280 284
281 expectTestsPass('the onComplete queue is run after an out-of-band error', () { 285 expectTestsPass('the onComplete queue is run after an out-of-band error', () {
282 var onCompleteRun = false; 286 var onCompleteRun = false;
283 test('test 1', () { 287 test('test 1', () {
284 currentSchedule.onComplete.schedule(() { 288 currentSchedule.onComplete.schedule(() {
285 onCompleteRun = true; 289 onCompleteRun = true;
286 }); 290 });
287 291
288 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar')))); 292 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar'))));
289 }); 293 });
290 294
291 test('test 2', () { 295 test('test 2', () {
292 expect(onCompleteRun, isTrue); 296 expect(onCompleteRun, isTrue);
293 }); 297 });
294 }, passing: ['test 2']); 298 }, passing: ['test 2']);
295 299
296 expectTestsPass('currentSchedule.errors contains the error in the onComplete ' 300 expectTestsPass('currentSchedule.errors contains the error in the onComplete '
297 'queue', () { 301 'queue', () {
298 var errors; 302 var errors;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 }); 384 });
381 }, passing: ['test 2']); 385 }, passing: ['test 2']);
382 386
383 expectTestsPass('the onException queue is run after an out-of-band error', () { 387 expectTestsPass('the onException queue is run after an out-of-band error', () {
384 var onExceptionRun = false; 388 var onExceptionRun = false;
385 test('test 1', () { 389 test('test 1', () {
386 currentSchedule.onException.schedule(() { 390 currentSchedule.onException.schedule(() {
387 onExceptionRun = true; 391 onExceptionRun = true;
388 }); 392 });
389 393
390 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar')))); 394 pumpEventQueue().then(wrapAsync((_) => expect('foo', equals('bar'))));
391 }); 395 });
392 396
393 test('test 2', () { 397 test('test 2', () {
394 expect(onExceptionRun, isTrue); 398 expect(onExceptionRun, isTrue);
395 }); 399 });
396 }, passing: ['test 2']); 400 }, passing: ['test 2']);
397 401
398 expectTestsPass('currentSchedule.errors contains the error in the ' 402 expectTestsPass('currentSchedule.errors contains the error in the '
399 'onException queue', () { 403 'onException queue', () {
400 var errors; 404 var errors;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 }, passing: ['test 2']); 451 }, passing: ['test 2']);
448 452
449 expectTestsPass('currentSchedule.errors contains an error passed into ' 453 expectTestsPass('currentSchedule.errors contains an error passed into '
450 'signalError out-of-band', () { 454 'signalError out-of-band', () {
451 var errors; 455 var errors;
452 test('test 1', () { 456 test('test 1', () {
453 currentSchedule.onException.schedule(() { 457 currentSchedule.onException.schedule(() {
454 errors = currentSchedule.errors; 458 errors = currentSchedule.errors;
455 }); 459 });
456 460
457 sleep(50).then(wrapAsync((_) => currentSchedule.signalError('error'))); 461 pumpEventQueue().then(wrapAsync((_) {
462 return currentSchedule.signalError('error');
463 }));
458 }); 464 });
459 465
460 test('test 2', () { 466 test('test 2', () {
461 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 467 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
462 expect(errors.map((e) => e.error), equals(['error'])); 468 expect(errors.map((e) => e.error), equals(['error']));
463 }); 469 });
464 }, passing: ['test 2']); 470 }, passing: ['test 2']);
465 471
466 expectTestsPass('currentSchedule.errors contains errors from both the task ' 472 expectTestsPass('currentSchedule.errors contains errors from both the task '
467 'queue and the onException queue in onComplete', () { 473 'queue and the onException queue in onComplete', () {
(...skipping 18 matching lines...) Expand all
486 492
487 expectTestsPass('currentSchedule.errors contains multiple out-of-band errors ' 493 expectTestsPass('currentSchedule.errors contains multiple out-of-band errors '
488 'from both the main task queue and onException in onComplete', () { 494 'from both the main task queue and onException in onComplete', () {
489 var errors; 495 var errors;
490 test('test 1', () { 496 test('test 1', () {
491 currentSchedule.onComplete.schedule(() { 497 currentSchedule.onComplete.schedule(() {
492 errors = currentSchedule.errors; 498 errors = currentSchedule.errors;
493 }); 499 });
494 500
495 currentSchedule.onException.schedule(() { 501 currentSchedule.onException.schedule(() {
496 sleep(25).then(wrapAsync((_) { 502 var exceptionWaiter = new Waiter();
503 exceptionWaiter.wait(1).then(wrapAsync((_) {
497 throw 'error3'; 504 throw 'error3';
498 })); 505 }));
499 sleep(50).then(wrapAsync((_) { 506 exceptionWaiter.wait(2).then(wrapAsync((_) {
500 throw 'error4'; 507 throw 'error4';
501 })); 508 }));
502 }); 509 });
503 510
504 sleep(25).then(wrapAsync((_) { 511 var waiter = new Waiter();
512 waiter.wait(1).then(wrapAsync((_) {
505 throw 'error1'; 513 throw 'error1';
506 })); 514 }));
507 sleep(50).then(wrapAsync((_) { 515 waiter.wait(2).then(wrapAsync((_) {
508 throw 'error2'; 516 throw 'error2';
509 })); 517 }));
510 }); 518 });
511 519
512 test('test 2', () { 520 test('test 2', () {
513 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 521 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
514 expect(errors.map((e) => e.error), 522 expect(errors.map((e) => e.error),
515 orderedEquals(['error1', 'error2', 'error3', 'error4'])); 523 orderedEquals(['error1', 'error2', 'error3', 'error4']));
516 }); 524 });
517 }, passing: ['test 2']); 525 }, passing: ['test 2']);
518 526
519 expectTestsPass('currentSchedule.errors contains both an out-of-band error ' 527 expectTestsPass('currentSchedule.errors contains both an out-of-band error '
520 'and an error raised afterwards in a task', () { 528 'and an error raised afterwards in a task', () {
521 var errors; 529 var errors;
522 test('test 1', () { 530 test('test 1', () {
523 currentSchedule.onComplete.schedule(() { 531 currentSchedule.onComplete.schedule(() {
524 errors = currentSchedule.errors; 532 errors = currentSchedule.errors;
525 }); 533 });
526 534
527 sleep(25).then(wrapAsync((_) { 535 var waiter = new Waiter();
536 waiter.wait(1).then(wrapAsync((_) {
528 throw 'out-of-band'; 537 throw 'out-of-band';
529 })); 538 }));
530 539
531 schedule(() => sleep(50).then((_) { 540 schedule(() => waiter.wait(2).then((_) {
532 throw 'in-band'; 541 throw 'in-band';
533 })); 542 }));
534 }); 543 });
535 544
536 test('test 2', () { 545 test('test 2', () {
537 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 546 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
538 expect(errors.map((e) => e.error), equals(['out-of-band', 'in-band'])); 547 expect(errors.map((e) => e.error), equals(['out-of-band', 'in-band']));
539 }); 548 });
540 }, passing: ['test 2']); 549 }, passing: ['test 2']);
541 550
(...skipping 16 matching lines...) Expand all
558 schedule(() => expect('foo', equals('foo'))); 567 schedule(() => expect('foo', equals('foo')));
559 568
560 expect(currentSchedule.currentTask, isNull); 569 expect(currentSchedule.currentTask, isNull);
561 }); 570 });
562 }); 571 });
563 572
564 expectTestsPass('currentSchedule.currentTask is null after the schedule has ' 573 expectTestsPass('currentSchedule.currentTask is null after the schedule has '
565 'completed', () { 574 'completed', () {
566 test('test', () { 575 test('test', () {
567 schedule(() { 576 schedule(() {
568 expect(sleep(50).then((_) { 577 expect(pumpEventQueue().then((_) {
569 expect(currentSchedule.currentTask, isNull); 578 expect(currentSchedule.currentTask, isNull);
570 }), completes); 579 }), completes);
571 }); 580 });
572 581
573 schedule(() => expect('foo', equals('foo'))); 582 schedule(() => expect('foo', equals('foo')));
574 }); 583 });
575 }); 584 });
576 585
577 expectTestsPass('currentSchedule.currentQueue returns the current queue while ' 586 expectTestsPass('currentSchedule.currentQueue returns the current queue while '
578 'executing a task', () { 587 'executing a task', () {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 }); 722 });
714 }); 723 });
715 724
716 group('group 2', () { 725 group('group 2', () {
717 test('test 2', () { 726 test('test 2', () {
718 expect(setUpRun, isFalse); 727 expect(setUpRun, isFalse);
719 }); 728 });
720 }); 729 });
721 }); 730 });
722 } 731 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/test/metatest.dart ('k') | pkg/scheduled_test/test/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698