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