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

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

Issue 12226103: Revert "Add built-in timeouts to scheduled_test." (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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 576
577 expectTestsPass('currentSchedule.currentQueue returns the current queue while ' 577 expectTestsPass('currentSchedule.currentQueue returns the current queue while '
578 'executing a task', () { 578 'executing a task', () {
579 test('test', () { 579 test('test', () {
580 schedule(() { 580 schedule(() {
581 expect(currentSchedule.currentQueue.name, equals('tasks')); 581 expect(currentSchedule.currentQueue.name, equals('tasks'));
582 }); 582 });
583 }); 583 });
584 }); 584 });
585 585
586 expectTestsPass('currentSchedule.currentQueue is tasks before the schedule ' 586 expectTestsPass('currentSchedule.currentQueue is null before the schedule has '
587 'has started', () { 587 'started', () {
588 test('test', () { 588 test('test', () {
589 schedule(() => expect('foo', equals('foo'))); 589 schedule(() => expect('foo', equals('foo')));
590 590
591 expect(currentSchedule.currentQueue.name, equals('tasks')); 591 expect(currentSchedule.currentQueue, isNull);
592 }); 592 });
593 }); 593 });
594 594
595 expectTestsPass('currentSchedule.state starts out as SET_UP', () {
596 test('test', () {
597 expect(currentSchedule.state, equals(ScheduleState.SET_UP));
598 });
599 });
600
601 expectTestsPass('currentSchedule.state is RUNNING in tasks', () {
602 test('test', () {
603 schedule(() {
604 expect(currentSchedule.state, equals(ScheduleState.RUNNING));
605 });
606
607 currentSchedule.onComplete.schedule(() {
608 expect(currentSchedule.state, equals(ScheduleState.RUNNING));
609 });
610 });
611 });
612
613 expectTestsPass('currentSchedule.state is DONE after the test', () {
614 var oldSchedule;
615 test('test 1', () {
616 oldSchedule = currentSchedule;
617 });
618
619 test('test 2', () {
620 expect(oldSchedule.state, equals(ScheduleState.DONE));
621 });
622 });
623
624 expectTestsPass('setUp is run before each test', () { 595 expectTestsPass('setUp is run before each test', () {
625 var setUpRun = false; 596 var setUpRun = false;
626 setUp(() { 597 setUp(() {
627 setUpRun = true; 598 setUpRun = true;
628 }); 599 });
629 600
630 test('test 1', () { 601 test('test 1', () {
631 expect(setUpRun, isTrue); 602 expect(setUpRun, isTrue);
632 setUpRun = false; 603 setUpRun = false;
633 }); 604 });
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 expect(setUpRun, isTrue); 712 expect(setUpRun, isTrue);
742 }); 713 });
743 }); 714 });
744 715
745 group('group 2', () { 716 group('group 2', () {
746 test('test 2', () { 717 test('test 2', () {
747 expect(setUpRun, isFalse); 718 expect(setUpRun, isFalse);
748 }); 719 });
749 }); 720 });
750 }); 721 });
751
752 expectTestsPass("a single task that takes too long will cause a timeout "
753 "error", () {
754 var errors;
755 test('test 1', () {
756 currentSchedule.timeoutMs = 50;
757
758 currentSchedule.onException.schedule(() {
759 errors = currentSchedule.errors;
760 });
761
762 schedule(() => sleep(60));
763 });
764
765 test('test 2', () {
766 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
767 expect(errors.map((e) => e.error), equals(["The schedule timed out after "
768 "50ms of inactivity."]));
769 });
770 }, passing: ['test 2']);
771
772 expectTestsPass("an out-of-band callback that takes too long will cause a "
773 "timeout error", () {
774 var errors;
775 test('test 1', () {
776 currentSchedule.timeoutMs = 50;
777
778 currentSchedule.onException.schedule(() {
779 errors = currentSchedule.errors;
780 });
781
782 sleep(60).then(wrapAsync((_) => expect('foo', equals('foo'))));
783 });
784
785 test('test 2', () {
786 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
787 expect(errors.map((e) => e.error), equals(["The schedule timed out after "
788 "50ms of inactivity."]));
789 });
790 }, passing: ['test 2']);
791
792 expectTestsPass("each task resets the timeout timer", () {
793 test('test', () {
794 currentSchedule.timeoutMs = 50;
795
796 schedule(() => sleep(30));
797 schedule(() => sleep(30));
798 schedule(() => sleep(30));
799 });
800 });
801
802 expectTestsPass("setting up the test doesn't trigger a timeout", () {
803 test('test', () {
804 currentSchedule.timeoutMs = 20;
805
806 var end = new DateTime.now().add(new Duration(milliseconds: 50));
807 while (new DateTime.now() < end) {}
808 schedule(() => expect('foo', equals('foo')));
809 });
810 });
811
812 expectTestsPass("an out-of-band error that's signaled after a timeout but "
813 "before the test completes is registered", () {
814 var errors;
815 test('test 1', () {
816 currentSchedule.timeoutMs = 50;
817
818 currentSchedule.onException.schedule(() => sleep(30));
819 currentSchedule.onException.schedule(() {
820 errors = currentSchedule.errors;
821 });
822
823 sleep(60).then(wrapAsync((_) {
824 throw 'out-of-band';
825 }));
826 });
827
828 test('test 2', () {
829 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
830 expect(errors.map((e) => e.error), equals([
831 "The schedule timed out after 50ms of inactivity.",
832 "out-of-band"
833 ]));
834 });
835 }, passing: ['test 2']);
836
837 expectTestsPass("an out-of-band error that's signaled after a timeout but "
838 "before the test completes plays nicely with other out-of-band callbacks",
839 () {
840 var errors;
841 var onExceptionCallbackRun = false;
842 var onCompleteRunAfterOnExceptionCallback = false;
843 test('test 1', () {
844 currentSchedule.timeoutMs = 50;
845
846 currentSchedule.onException.schedule(() {
847 sleep(30).then(wrapAsync((_) {
848 onExceptionCallbackRun = true;
849 }));
850 });
851
852 currentSchedule.onComplete.schedule(() {
853 onCompleteRunAfterOnExceptionCallback = onExceptionCallbackRun;
854 });
855
856 sleep(60).then(wrapAsync((_) {
857 throw 'out-of-band';
858 }));
859 });
860
861 test('test 2', () {
862 expect(onCompleteRunAfterOnExceptionCallback, isTrue);
863 });
864 }, passing: ['test 2']);
865
866 expectTestsPass("a task that times out while waiting to handle an "
867 "out-of-band error records both", () {
868 var errors;
869 test('test 1', () {
870 currentSchedule.timeoutMs = 50;
871
872 currentSchedule.onException.schedule(() {
873 errors = currentSchedule.errors;
874 });
875
876 schedule(() => sleep(60));
877 sleep(10).then((_) => currentSchedule.signalError('out-of-band'));
878 });
879
880 test('test 2', () {
881 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
882 expect(errors.map((e) => e.error), equals([
883 "out-of-band",
884 "The schedule timed out after 50ms of inactivity."
885 ]));
886 });
887 }, passing: ['test 2']);
888
889 expectTestsPass("currentSchedule.heartbeat resets the timeout timer", () {
890 test('test', () {
891 currentSchedule.timeoutMs = 50;
892
893 schedule(() {
894 return sleep(30).then((_) {
895 currentSchedule.heartbeat();
896 return sleep(30);
897 });
898 });
899 });
900 });
901
902 // TODO(nweiz): test out-of-band post-timeout errors that are detected after
903 // the test finishes once we can detect top-level errors (issue 8417).
904 } 722 }
OLDNEW
« no previous file with comments | « pkg/scheduled_test/lib/src/substitute_future.dart ('k') | pkg/scheduled_test/test/substitute_future_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698