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

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

Issue 12217122: Re-submit r18349. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
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 import 'package:scheduled_test/src/utils.dart';
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 test('asynchronous value', () { 88 test('asynchronous value', () {
89 var future = schedule(() => new Future.immediate('value')); 89 var future = schedule(() => new Future.immediate('value'));
90 expect(future, completion(equals('value'))); 90 expect(future, completion(equals('value')));
91 }); 91 });
92 }); 92 });
93 93
94 expectTestsPass('scheduled blocks should wait for their Future return values ' 94 expectTestsPass('scheduled blocks should wait for their Future return values '
95 'to complete before proceeding', () { 95 'to complete before proceeding', () {
96 test('test', () { 96 test('test', () {
97 var value = 'unset'; 97 var value = 'unset';
98 schedule(() => sleep(500).then((_) { 98 schedule(() => sleep(50).then((_) {
99 value = 'set'; 99 value = 'set';
100 })); 100 }));
101 schedule(() => expect(value, equals('set'))); 101 schedule(() => expect(value, equals('set')));
102 }); 102 });
103 }); 103 });
104 104
105 expectTestsFail('a test failure in a chained future in a scheduled block ' 105 expectTestsFail('a test failure in a chained future in a scheduled block '
106 'should be registered', () { 106 'should be registered', () {
107 test('test', () { 107 test('test', () {
108 schedule(() => new Future.immediate('foo') 108 schedule(() => new Future.immediate('foo')
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 }); 286 });
287 287
288 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar')))); 288 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar'))));
289 }); 289 });
290 290
291 test('test 2', () { 291 test('test 2', () {
292 expect(onCompleteRun, isTrue); 292 expect(onCompleteRun, isTrue);
293 }); 293 });
294 }, passing: ['test 2']); 294 }, passing: ['test 2']);
295 295
296 expectTestsPass('currentSchedule.error contains the error in the onComplete ' 296 expectTestsPass('currentSchedule.errors contains the error in the onComplete '
297 'queue', () { 297 'queue', () {
298 var error; 298 var errors;
299 test('test 1', () { 299 test('test 1', () {
300 currentSchedule.onComplete.schedule(() { 300 currentSchedule.onComplete.schedule(() {
301 error = currentSchedule.error; 301 errors = currentSchedule.errors;
302 }); 302 });
303 303
304 throw 'error'; 304 throw 'error';
305 }); 305 });
306 306
307 test('test 2', () { 307 test('test 2', () {
308 expect(error, new isInstanceOf<ScheduleError>()); 308 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
309 expect(error.error, equals('error')); 309 expect(errors.map((e) => e.error), equals(['error']));
310 }); 310 });
311 }, passing: ['test 2']); 311 }, passing: ['test 2']);
312 312
313 expectTestsPass('onComplete tasks can be scheduled during normal tasks', () { 313 expectTestsPass('onComplete tasks can be scheduled during normal tasks', () {
314 var onCompleteRun = false; 314 var onCompleteRun = false;
315 test('test 1', () { 315 test('test 1', () {
316 schedule(() { 316 schedule(() {
317 currentSchedule.onComplete.schedule(() { 317 currentSchedule.onComplete.schedule(() {
318 onCompleteRun = true; 318 onCompleteRun = true;
319 }); 319 });
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 }); 388 });
389 389
390 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar')))); 390 sleep(50).then(wrapAsync((_) => expect('foo', equals('bar'))));
391 }); 391 });
392 392
393 test('test 2', () { 393 test('test 2', () {
394 expect(onExceptionRun, isTrue); 394 expect(onExceptionRun, isTrue);
395 }); 395 });
396 }, passing: ['test 2']); 396 }, passing: ['test 2']);
397 397
398 expectTestsPass('currentSchedule.error contains the error in the onException ' 398 expectTestsPass('currentSchedule.errors contains the error in the '
399 'queue', () { 399 'onException queue', () {
400 var error; 400 var errors;
401 test('test 1', () { 401 test('test 1', () {
402 currentSchedule.onException.schedule(() { 402 currentSchedule.onException.schedule(() {
403 error = currentSchedule.error; 403 errors = currentSchedule.errors;
404 }); 404 });
405 405
406 throw 'error'; 406 throw 'error';
407 }); 407 });
408 408
409 test('test 2', () { 409 test('test 2', () {
410 expect(error, new isInstanceOf<ScheduleError>()); 410 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
411 expect(error.error, equals('error')); 411 expect(errors.map((e) => e.error), equals(['error']));
412 }); 412 });
413 }, passing: ['test 2']); 413 }, passing: ['test 2']);
414 414
415 expectTestsPass('currentSchedule.error contains an error passed into ' 415 expectTestsPass('currentSchedule.errors contains an error passed into '
416 'signalError synchronously', () { 416 'signalError synchronously', () {
417 var error; 417 var errors;
418 test('test 1', () { 418 test('test 1', () {
419 currentSchedule.onException.schedule(() { 419 currentSchedule.onException.schedule(() {
420 error = currentSchedule.error; 420 errors = currentSchedule.errors;
421 }); 421 });
422 422
423 currentSchedule.signalError('error'); 423 currentSchedule.signalError('error');
424 }); 424 });
425 425
426 test('test 2', () { 426 test('test 2', () {
427 expect(error, new isInstanceOf<ScheduleError>()); 427 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
428 expect(error.error, equals('error')); 428 expect(errors.map((e) => e.error), equals(['error']));
429 }); 429 });
430 }, passing: ['test 2']); 430 }, passing: ['test 2']);
431 431
432 expectTestsPass('currentSchedule.error contains an error passed into ' 432 expectTestsPass('currentSchedule.errors contains an error passed into '
433 'signalError asynchronously', () { 433 'signalError asynchronously', () {
434 var error; 434 var errors;
435 test('test 1', () { 435 test('test 1', () {
436 currentSchedule.onException.schedule(() { 436 currentSchedule.onException.schedule(() {
437 error = currentSchedule.error; 437 errors = currentSchedule.errors;
438 }); 438 });
439 439
440 schedule(() => currentSchedule.signalError('error')); 440 schedule(() => currentSchedule.signalError('error'));
441 }); 441 });
442 442
443 test('test 2', () { 443 test('test 2', () {
444 expect(error, new isInstanceOf<ScheduleError>()); 444 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
445 expect(error.error, equals('error')); 445 expect(errors.map((e) => e.error), equals(['error']));
446 }); 446 });
447 }, passing: ['test 2']); 447 }, passing: ['test 2']);
448 448
449 expectTestsPass('currentSchedule.error contains an error passed into ' 449 expectTestsPass('currentSchedule.errors contains an error passed into '
450 'signalError out-of-band', () { 450 'signalError out-of-band', () {
451 var error; 451 var errors;
452 test('test 1', () { 452 test('test 1', () {
453 currentSchedule.onException.schedule(() { 453 currentSchedule.onException.schedule(() {
454 error = currentSchedule.error; 454 errors = currentSchedule.errors;
455 }); 455 });
456 456
457 sleep(50).then(wrapAsync((_) => currentSchedule.signalError('error'))); 457 sleep(50).then(wrapAsync((_) => currentSchedule.signalError('error')));
458 }); 458 });
459 459
460 test('test 2', () { 460 test('test 2', () {
461 expect(error, new isInstanceOf<ScheduleError>()); 461 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
462 expect(error.error, equals('error')); 462 expect(errors.map((e) => e.error), equals(['error']));
463 }); 463 });
464 }, passing: ['test 2']); 464 }, passing: ['test 2']);
465 465
466 expectTestsPass('currentSchedule.errors contains errors from both the task '
467 'queue and the onException queue in onComplete', () {
468 var errors;
469 test('test 1', () {
470 currentSchedule.onComplete.schedule(() {
471 errors = currentSchedule.errors;
472 });
473
474 currentSchedule.onException.schedule(() {
475 throw 'error2';
476 });
477
478 throw 'error1';
479 });
480
481 test('test 2', () {
482 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
483 expect(errors.map((e) => e.error), equals(['error1', 'error2']));
484 });
485 }, passing: ['test 2']);
486
487 expectTestsPass('currentSchedule.errors contains multiple out-of-band errors '
488 'from both the main task queue and onException in onComplete', () {
489 var errors;
490 test('test 1', () {
491 currentSchedule.onComplete.schedule(() {
492 errors = currentSchedule.errors;
493 });
494
495 currentSchedule.onException.schedule(() {
496 sleep(25).then(wrapAsync((_) {
497 throw 'error3';
498 }));
499 sleep(50).then(wrapAsync((_) {
500 throw 'error4';
501 }));
502 });
503
504 sleep(25).then(wrapAsync((_) {
505 throw 'error1';
506 }));
507 sleep(50).then(wrapAsync((_) {
508 throw 'error2';
509 }));
510 });
511
512 test('test 2', () {
513 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
514 expect(errors.map((e) => e.error),
515 orderedEquals(['error1', 'error2', 'error3', 'error4']));
516 });
517 }, passing: ['test 2']);
518
519 expectTestsPass('currentSchedule.errors contains both an out-of-band error '
520 'and an error raised afterwards in a task', () {
521 var errors;
522 test('test 1', () {
523 currentSchedule.onComplete.schedule(() {
524 errors = currentSchedule.errors;
525 });
526
527 sleep(25).then(wrapAsync((_) {
528 throw 'out-of-band';
529 }));
530
531 schedule(() => sleep(50).then((_) {
532 throw 'in-band';
533 }));
534 });
535
536 test('test 2', () {
537 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
538 expect(errors.map((e) => e.error), equals(['out-of-band', 'in-band']));
539 });
540 }, passing: ['test 2']);
541
466 expectTestsPass('currentSchedule.currentTask returns the current task while ' 542 expectTestsPass('currentSchedule.currentTask returns the current task while '
467 'executing a task', () { 543 'executing a task', () {
468 test('test', () { 544 test('test', () {
469 schedule(() => expect('foo', equals('foo')), 'task 1'); 545 schedule(() => expect('foo', equals('foo')), 'task 1');
470 546
471 schedule(() { 547 schedule(() {
472 expect(currentSchedule.currentTask.description, equals('task 2')); 548 expect(currentSchedule.currentTask.description, equals('task 2'));
473 }, 'task 2'); 549 }, 'task 2');
474 550
475 schedule(() => expect('bar', equals('bar')), 'task 3'); 551 schedule(() => expect('bar', equals('bar')), 'task 3');
476 }); 552 });
477 }); 553 });
478 554
479 expectTestsPass('currentSchedule.currentTask is null before the schedule has ' 555 expectTestsPass('currentSchedule.currentTask is null before the schedule has '
480 'started', () { 556 'started', () {
481 test('test', () { 557 test('test', () {
482 schedule(() => expect('foo', equals('foo'))); 558 schedule(() => expect('foo', equals('foo')));
483 559
484 expect(currentSchedule.currentTask, isNull); 560 expect(currentSchedule.currentTask, isNull);
485 }); 561 });
486 }); 562 });
487 563
488 expectTestsPass('currentSchedule.currentTask is null after the schedule has ' 564 expectTestsPass('currentSchedule.currentTask is null after the schedule has '
489 'completed', () { 565 'completed', () {
490 test('test', () { 566 test('test', () {
491 expect(sleep(50).then((_) { 567 schedule(() {
492 expect(currentSchedule.currentTask, isNull); 568 expect(sleep(50).then((_) {
493 }), completes); 569 expect(currentSchedule.currentTask, isNull);
570 }), completes);
571 });
494 572
495 schedule(() => expect('foo', equals('foo'))); 573 schedule(() => expect('foo', equals('foo')));
496 }); 574 });
497 }); 575 });
498 576
499 expectTestsPass('currentSchedule.currentQueue returns the current queue while ' 577 expectTestsPass('currentSchedule.currentQueue returns the current queue while '
500 'executing a task', () { 578 'executing a task', () {
501 test('test', () { 579 test('test', () {
502 schedule(() { 580 schedule(() {
503 expect(currentSchedule.currentQueue.name, equals('tasks')); 581 expect(currentSchedule.currentQueue.name, equals('tasks'));
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 }); 713 });
636 }); 714 });
637 715
638 group('group 2', () { 716 group('group 2', () {
639 test('test 2', () { 717 test('test 2', () {
640 expect(setUpRun, isFalse); 718 expect(setUpRun, isFalse);
641 }); 719 });
642 }); 720 });
643 }); 721 });
644 } 722 }
OLDNEW
« pkg/scheduled_test/lib/src/utils.dart ('K') | « pkg/scheduled_test/lib/src/utils.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698