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

Unified Diff: pkg/scheduled_test/test/scheduled_test_test.dart

Issue 12288061: Support nested tasks in scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/scheduled_test/lib/src/task.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/scheduled_test/test/scheduled_test_test.dart
diff --git a/pkg/scheduled_test/test/scheduled_test_test.dart b/pkg/scheduled_test/test/scheduled_test_test.dart
index dcf5beac590d78d6a0a3133f89ae8f4835ed57ea..f07024da23168039f24ef18c40c496926ccdfdb6 100644
--- a/pkg/scheduled_test/test/scheduled_test_test.dart
+++ b/pkg/scheduled_test/test/scheduled_test_test.dart
@@ -142,6 +142,74 @@ void main() {
});
});
+ expectTestsFail('an out-of-band failure in wrapFuture is handled', () {
+ mock_clock.mock().run();
+ test('test', () {
+ schedule(() {
+ wrapFuture(sleep(1).then((_) => expect('foo', equals('bar'))));
+ });
+ schedule(() => sleep(2));
+ });
+ });
+
+ expectTestsFail('an out-of-band failure in wrapFuture that finishes after '
+ 'the schedule is handled', () {
+ mock_clock.mock().run();
+ test('test', () {
+ schedule(() {
+ wrapFuture(sleep(2).then((_) => expect('foo', equals('bar'))));
+ });
+ schedule(() => sleep(1));
+ });
+ });
+
+ expectTestsPass("wrapFuture should return the value of the wrapped future",
+ () {
+ test('test', () {
+ schedule(() {
+ expect(wrapFuture(pumpEventQueue().then((_) => 'foo')),
+ completion(equals('foo')));
+ });
+ });
+ });
+
+ expectTestsPass("wrapFuture should pass through the error of the wrapped "
+ "future", () {
+ var error;
+ test('test 1', () {
+ schedule(() {
+ wrapFuture(pumpEventQueue().then((_) {
+ throw 'error';
+ })).catchError(wrapAsync((e) {
+ error = e.error;
+ }));
+ });
+ });
+
+ test('test 2', () {
+ expect(error, equals('error'));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass("scheduled blocks whose return values are passed to "
+ "wrapFuture should report exceptions once", () {
+ var errors;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ errors = currentSchedule.errors;
+ });
+
+ wrapFuture(schedule(() {
+ throw 'error';
+ }));
+ });
+
+ test('test 2', () {
+ expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
+ expect(errors.map((e) => e.error), equals(['error']));
+ });
+ }, passing: ['test 2']);
+
expectTestsFail('an out-of-band error reported via signalError is '
'handled', () {
mock_clock.mock().run();
@@ -524,6 +592,40 @@ void main() {
});
}, passing: ['test 2']);
+ expectTestsPass('currentSchedule.errors contains multiple out-of-band errors '
+ 'from both the main task queue and onException in onComplete reported '
+ 'via wrapFuture', () {
+ mock_clock.mock().run();
+ var errors;
+ test('test 1', () {
+ currentSchedule.onComplete.schedule(() {
+ errors = currentSchedule.errors;
+ });
+
+ currentSchedule.onException.schedule(() {
+ wrapFuture(sleep(1).then((_) {
+ throw 'error3';
+ }));
+ wrapFuture(sleep(2).then((_) {
+ throw 'error4';
+ }));
+ });
+
+ wrapFuture(sleep(1).then((_) {
+ throw 'error1';
+ }));
+ wrapFuture(sleep(2).then((_) {
+ throw 'error2';
+ }));
+ });
+
+ test('test 2', () {
+ expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
+ expect(errors.map((e) => e.error),
+ orderedEquals(['error1', 'error2', 'error3', 'error4']));
+ });
+ }, passing: ['test 2']);
+
expectTestsPass('currentSchedule.errors contains both an out-of-band error '
'and an error raised afterwards in a task', () {
mock_clock.mock().run();
@@ -917,4 +1019,158 @@ void main() {
// TODO(nweiz): test out-of-band post-timeout errors that are detected after
// the test finishes once we can detect top-level errors (issue 8417).
+
+ expectTestsPass("nested schedule() runs its function immediately (but "
+ "asynchronously)", () {
+ test('test', () {
+ schedule(() {
+ var nestedScheduleRun = false;
+ schedule(() {
+ nestedScheduleRun = true;
+ });
+
+ expect(nestedScheduleRun, isFalse);
+ expect(pumpEventQueue().then((_) => nestedScheduleRun),
+ completion(isTrue));
+ });
+ });
+ });
+
+ expectTestsPass("out-of-band schedule() runs its function immediately (but "
+ "asynchronously)", () {
+ mock_clock.mock().run();
+ test('test', () {
+ schedule(() {
+ wrapFuture(sleep(1).then((_) {
+ var nestedScheduleRun = false;
+ schedule(() {
+ nestedScheduleRun = true;
+ });
+
+ expect(nestedScheduleRun, isFalse);
+ expect(pumpEventQueue().then((_) => nestedScheduleRun),
+ completion(isTrue));
+ }));
+ });
+ });
+ });
+
+ expectTestsPass("nested schedule() calls don't wait for one another", () {
+ mock_clock.mock().run();
+ test('test', () {
+ var sleepFinished = false;
+ schedule(() {
+ schedule(() => sleep(1).then((_) {
+ sleepFinished = true;
+ }));
+ schedule(() => expect(sleepFinished, isFalse));
+ });
+ });
+ });
+
+ expectTestsPass("nested schedule() calls block their parent task", () {
+ mock_clock.mock().run();
+ test('test', () {
+ var sleepFinished = false;
+ schedule(() {
+ schedule(() => sleep(1).then((_) {
+ sleepFinished = true;
+ }));
+ });
+
+ schedule(() => expect(sleepFinished, isTrue));
+ });
+ });
+
+ expectTestsPass("out-of-band schedule() calls block their parent queue", () {
+ mock_clock.mock().run();
+ test('test', () {
+ var scheduleRun = false;
+ wrapFuture(sleep(1).then((_) {
+ schedule(() => sleep(1).then((_) {
+ scheduleRun = true;
+ }));
+ }));
+
+ currentSchedule.onComplete.schedule(() => expect(scheduleRun, isTrue));
+ });
+ });
+
+ expectTestsPass("nested schedule() calls forward their Future values", () {
+ mock_clock.mock().run();
+ test('test', () {
+ schedule(() {
+ expect(schedule(() => 'foo'), completion(equals('foo')));
+ });
+ });
+ });
+
+ expectTestsPass("errors in nested schedule() calls are properly registered",
+ () {
+ var errors;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ errors = currentSchedule.errors;
+ });
+
+ schedule(() {
+ schedule(() {
+ throw 'error';
+ });
+ });
+ });
+
+ test('test 2', () {
+ expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
+ expect(errors.map((e) => e.error), equals(['error']));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass("nested scheduled blocks whose return values are passed to "
+ "wrapFuture should report exceptions once", () {
+ var errors;
+ test('test 1', () {
+ currentSchedule.onException.schedule(() {
+ errors = currentSchedule.errors;
+ });
+
+ schedule(() {
+ wrapFuture(schedule(() {
+ throw 'error';
+ }));
+
+ return pumpEventQueue();
+ });
+ });
+
+ test('test 2', () {
+ expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
+ expect(errors.map((e) => e.error), equals(['error']));
+ });
+ }, passing: ['test 2']);
+
+ expectTestsPass("a nested task failing shouldn't short-circuit the parent "
+ "task", () {
+ var parentTaskFinishedBeforeOnComplete = false;
+ test('test 1', () {
+ var parentTaskFinished = false;
+ currentSchedule.onComplete.schedule(() {
+ parentTaskFinishedBeforeOnComplete = parentTaskFinished;
+ });
+
+ schedule(() {
+ schedule(() {
+ throw 'error';
+ });
+
+ return sleep(1).then((_) {
+ parentTaskFinished = true;
+ });
+ });
+ });
+
+ test('test 2', () {
+ expect(parentTaskFinishedBeforeOnComplete, isTrue);
+ });
+ }, passing: ['test 2']);
}
« no previous file with comments | « pkg/scheduled_test/lib/src/task.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698