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

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

Issue 12377093: Add a ScheduledProcess class to pkg/scheduled_test. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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/mock_clock.dart' as mock_clock; 10 import 'package:scheduled_test/src/mock_clock.dart' as mock_clock;
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 throw 'in-band'; 643 throw 'in-band';
644 })); 644 }));
645 }); 645 });
646 646
647 test('test 2', () { 647 test('test 2', () {
648 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 648 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
649 expect(errors.map((e) => e.error), equals(['out-of-band', 'in-band'])); 649 expect(errors.map((e) => e.error), equals(['out-of-band', 'in-band']));
650 }); 650 });
651 }, passing: ['test 2']); 651 }, passing: ['test 2']);
652 652
653 expectTestsPass('currentSchedule.errors contains both an error raised in a '
654 'task and an error raised afterwards out-of-band', () {
655 mock_clock.mock().run();
656 var errors;
657 test('test 1', () {
658 currentSchedule.onComplete.schedule(() {
659 errors = currentSchedule.errors;
660 });
661
662 sleep(2).then(wrapAsync((_) {
663 throw 'out-of-band';
664 }));
665
666 schedule(() => sleep(1).then((_) {
667 throw 'in-band';
668 }));
669 });
670
671 test('test 2', () {
672 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
673 expect(errors.map((e) => e.error), equals(['in-band', 'out-of-band']));
674 });
675 }, passing: ['test 2']);
676
653 expectTestsPass('currentSchedule.currentTask returns the current task while ' 677 expectTestsPass('currentSchedule.currentTask returns the current task while '
654 'executing a task', () { 678 'executing a task', () {
655 test('test', () { 679 test('test', () {
656 schedule(() => expect('foo', equals('foo')), 'task 1'); 680 schedule(() => expect('foo', equals('foo')), 'task 1');
657 681
658 schedule(() { 682 schedule(() {
659 expect(currentSchedule.currentTask.description, equals('task 2')); 683 expect(currentSchedule.currentTask.description, equals('task 2'));
660 }, 'task 2'); 684 }, 'task 2');
661 685
662 schedule(() => expect('bar', equals('bar')), 'task 3'); 686 schedule(() => expect('bar', equals('bar')), 'task 3');
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 1020
997 test('test 2', () { 1021 test('test 2', () {
998 expect(errors, everyElement(new isInstanceOf<ScheduleError>())); 1022 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
999 expect(errors.map((e) => e.error), equals([ 1023 expect(errors.map((e) => e.error), equals([
1000 "out-of-band", 1024 "out-of-band",
1001 "The schedule timed out after 0:00:00.002000 of inactivity." 1025 "The schedule timed out after 0:00:00.002000 of inactivity."
1002 ])); 1026 ]));
1003 }); 1027 });
1004 }, passing: ['test 2']); 1028 }, passing: ['test 2']);
1005 1029
1030 expectTestsPass("a task that has an error then times out waiting for an "
1031 "out-of-band callback records both", () {
1032 mock_clock.mock().run();
1033 var errors;
1034 test('test 1', () {
1035 currentSchedule.timeout = new Duration(milliseconds: 2);
1036
1037 currentSchedule.onException.schedule(() {
1038 errors = currentSchedule.errors;
1039 });
1040
1041 schedule(() {
1042 throw 'error';
1043 });
1044 wrapFuture(sleep(3));
1045 });
1046
1047 test('test 2', () {
1048 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
1049 expect(errors.map((e) => e.error), equals([
1050 "error",
1051 "The schedule timed out after 0:00:00.002000 of inactivity."
1052 ]));
1053 });
1054 }, passing: ['test 2']);
1055
1006 expectTestsPass("currentSchedule.heartbeat resets the timeout timer", () { 1056 expectTestsPass("currentSchedule.heartbeat resets the timeout timer", () {
1007 mock_clock.mock().run(); 1057 mock_clock.mock().run();
1008 test('test', () { 1058 test('test', () {
1009 currentSchedule.timeout = new Duration(milliseconds: 3); 1059 currentSchedule.timeout = new Duration(milliseconds: 3);
1010 1060
1011 schedule(() { 1061 schedule(() {
1012 return sleep(2).then((_) { 1062 return sleep(2).then((_) {
1013 currentSchedule.heartbeat(); 1063 currentSchedule.heartbeat();
1014 return sleep(2); 1064 return sleep(2);
1015 }); 1065 });
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 return sleep(1).then((_) { 1216 return sleep(1).then((_) {
1167 parentTaskFinished = true; 1217 parentTaskFinished = true;
1168 }); 1218 });
1169 }); 1219 });
1170 }); 1220 });
1171 1221
1172 test('test 2', () { 1222 test('test 2', () {
1173 expect(parentTaskFinishedBeforeOnComplete, isTrue); 1223 expect(parentTaskFinishedBeforeOnComplete, isTrue);
1174 }); 1224 });
1175 }, passing: ['test 2']); 1225 }, passing: ['test 2']);
1226
1227 expectTestsPass("an error thrown in a scheduled task should be piped to that "
1228 "task's return value", () {
1229 var error;
1230 test('test 1', () {
1231 schedule(() {
1232 throw 'error';
1233 }).catchError((e) {
1234 error = e;
1235 });
1236 });
1237
1238 test('test 2', () {
1239 expect(error, new isInstanceOf<ScheduleError>());
1240 expect(error.error, equals('error'));
1241 });
1242 }, passing: ['test 2']);
1243
1244 expectTestsPass("an error thrown in a scheduled task should be piped to "
1245 "future tasks' return values", () {
1246 var error;
1247 test('test 1', () {
1248 schedule(() {
1249 throw 'error';
1250 });
1251
1252 schedule(() => null).catchError((e) {
1253 error = e;
1254 });
Bob Nystrom 2013/03/04 23:52:00 What's the motivation for this?
nweiz 2013/03/05 02:16:09 It's catching the error thrown by the return value
1255 });
1256
1257 test('test 2', () {
1258 expect(error, new isInstanceOf<ScheduleError>());
1259 expect(error.error, equals('error'));
1260 });
1261 }, passing: ['test 2']);
1262
1263 expectTestsPass("an out-of-band error should be piped to future tasks' "
1264 "return values, but not the current task's", () {
1265 mock_clock.mock().run();
1266 var error;
1267 var firstTaskError = false;
1268 var secondTaskRun = false;
1269 test('test 1', () {
1270 schedule(() => sleep(2)).catchError((_) {
1271 firstTaskError = true;
1272 });
1273
1274 sleep(1).then(wrapAsync((_) {
1275 throw 'error';
1276 }));
1277
1278 schedule(() {
1279 secondTaskRun = true;
1280 }).catchError((e) {
1281 error = e;
1282 });
1283 });
1284
1285 test('test 2', () {
1286 expect(firstTaskError, isFalse);
1287 expect(secondTaskRun, isFalse);
1288 expect(error, new isInstanceOf<ScheduleError>());
1289 expect(error.error, equals('error'));
1290 });
1291 }, passing: ['test 2']);
1292
1293 expectTestsPass("expect(..., completes) with a completing future should pass",
1294 () {
1295 test('test', () {
1296 expect(pumpEventQueue(), completes);
1297 });
1298 });
1299
1300 expectTestsPass("expect(..., completes) with a failing future should signal "
1301 "an out-of-band error", () {
1302 var errors;
1303 test('test 1', () {
1304 currentSchedule.onException.schedule(() {
1305 errors = currentSchedule.errors;
1306 });
1307
1308 expect(pumpEventQueue().then((_) {
1309 throw 'error';
1310 }), completes);
1311 });
1312
1313 test('test 2', () {
1314 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
1315 expect(errors.map((e) => e.error), equals(['error']));
1316 });
1317 }, passing: ['test 2']);
1318
1319 expectTestsPass("expect(..., completion(...)) with a matching future should "
1320 "pass", () {
1321 test('test', () {
1322 expect(pumpEventQueue().then((_) => 'foo'), completion(equals('foo')));
1323 });
1324 });
1325
1326 expectTestsPass("expect(..., completion(...)) with a non-matching future "
1327 "should signal an out-of-band error", () {
1328 var errors;
1329 test('test 1', () {
1330 currentSchedule.onException.schedule(() {
1331 errors = currentSchedule.errors;
1332 });
1333
1334 expect(pumpEventQueue().then((_) => 'foo'), completion(equals('bar')));
1335 });
1336
1337 test('test 2', () {
1338 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
1339 expect(errors.length, equals(1));
1340 expect(errors.first.error, new isInstanceOf<TestFailure>());
1341 });
1342 }, passing: ['test 2']);
1343
1344 expectTestsPass("expect(..., completion(...)) with a failing future should "
1345 "signal an out-of-band error", () {
1346 var errors;
1347 test('test 1', () {
1348 currentSchedule.onException.schedule(() {
1349 errors = currentSchedule.errors;
1350 });
1351
1352 expect(pumpEventQueue().then((_) {
1353 throw 'error';
1354 }), completion(equals('bar')));
1355 });
1356
1357 test('test 2', () {
1358 expect(errors, everyElement(new isInstanceOf<ScheduleError>()));
1359 expect(errors.map((e) => e.error), equals(['error']));
1360 });
1361 }, passing: ['test 2']);
1176 } 1362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698