OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:fake_async/fake_async.dart'; | 7 import 'package:fake_async/fake_async.dart'; |
8 import 'package:test/src/backend/invoker.dart'; | 8 import 'package:test/src/backend/invoker.dart'; |
9 import 'package:test/src/backend/metadata.dart'; | 9 import 'package:test/src/backend/metadata.dart'; |
10 import 'package:test/src/backend/state.dart'; | 10 import 'package:test/src/backend/state.dart'; |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 outstandingCallbackRemovedBeforeTeardown = outstandingCallbackRemoved; | 466 outstandingCallbackRemovedBeforeTeardown = outstandingCallbackRemoved; |
467 }).load(suite); | 467 }).load(suite); |
468 | 468 |
469 liveTest.onError.listen(expectAsync((_) {}, count: 0)); | 469 liveTest.onError.listen(expectAsync((_) {}, count: 0)); |
470 | 470 |
471 return liveTest.run().then((_) { | 471 return liveTest.run().then((_) { |
472 expect(outstandingCallbackRemovedBeforeTeardown, isTrue); | 472 expect(outstandingCallbackRemovedBeforeTeardown, isTrue); |
473 }); | 473 }); |
474 }); | 474 }); |
475 | 475 |
476 test("a test times out after 30 seconds", () { | |
477 new FakeAsync().run((async) { | |
478 var liveTest = _localTest(() { | |
479 Invoker.current.addOutstandingCallback(); | |
480 }).load(suite); | |
481 | |
482 expectStates(liveTest, [ | |
483 const State(Status.running, Result.success), | |
484 const State(Status.complete, Result.error) | |
485 ]); | |
486 | |
487 expectErrors(liveTest, [(error) { | |
488 expect(lastState.status, equals(Status.complete)); | |
489 expect(error, new isInstanceOf<TimeoutException>()); | |
490 }]); | |
491 | |
492 liveTest.run(); | |
493 async.elapse(new Duration(seconds: 30)); | |
494 }); | |
495 }); | |
496 | |
497 test("a test's prints are captured and reported", () { | 476 test("a test's prints are captured and reported", () { |
498 expect(() { | 477 expect(() { |
499 var liveTest = _localTest(() { | 478 var liveTest = _localTest(() { |
500 print("Hello,"); | 479 print("Hello,"); |
501 return new Future(() => print("world!")); | 480 return new Future(() => print("world!")); |
502 }).load(suite); | 481 }).load(suite); |
503 | 482 |
504 expect(liveTest.onPrint.take(2).toList(), | 483 expect(liveTest.onPrint.take(2).toList(), |
505 completion(equals(["Hello,", "world!"]))); | 484 completion(equals(["Hello,", "world!"]))); |
506 | 485 |
507 return liveTest.run(); | 486 return liveTest.run(); |
508 }, prints(isEmpty)); | 487 }, prints(isEmpty)); |
509 }); | 488 }); |
| 489 |
| 490 group("timeout:", () { |
| 491 test("a test times out after 30 seconds by default", () { |
| 492 new FakeAsync().run((async) { |
| 493 var liveTest = _localTest(() { |
| 494 Invoker.current.addOutstandingCallback(); |
| 495 }).load(suite); |
| 496 |
| 497 expectStates(liveTest, [ |
| 498 const State(Status.running, Result.success), |
| 499 const State(Status.complete, Result.error) |
| 500 ]); |
| 501 |
| 502 expectErrors(liveTest, [(error) { |
| 503 expect(lastState.status, equals(Status.complete)); |
| 504 expect(error, new isInstanceOf<TimeoutException>()); |
| 505 }]); |
| 506 |
| 507 liveTest.run(); |
| 508 async.elapse(new Duration(seconds: 30)); |
| 509 }); |
| 510 }); |
| 511 |
| 512 test("a test's custom timeout takes precedence", () { |
| 513 new FakeAsync().run((async) { |
| 514 var liveTest = _localTest(() { |
| 515 Invoker.current.addOutstandingCallback(); |
| 516 }, metadata: new Metadata( |
| 517 timeout: new Timeout(new Duration(seconds: 15)))).load(suite); |
| 518 |
| 519 expectStates(liveTest, [ |
| 520 const State(Status.running, Result.success), |
| 521 const State(Status.complete, Result.error) |
| 522 ]); |
| 523 |
| 524 expectErrors(liveTest, [(error) { |
| 525 expect(lastState.status, equals(Status.complete)); |
| 526 expect(error, new isInstanceOf<TimeoutException>()); |
| 527 }]); |
| 528 |
| 529 liveTest.run(); |
| 530 async.elapse(new Duration(seconds: 15)); |
| 531 }); |
| 532 }); |
| 533 |
| 534 test("a timeout factor is applied on top of the 30s default", () { |
| 535 new FakeAsync().run((async) { |
| 536 var liveTest = _localTest(() { |
| 537 Invoker.current.addOutstandingCallback(); |
| 538 }, metadata: new Metadata(timeout: new Timeout.factor(0.5))) |
| 539 .load(suite); |
| 540 |
| 541 expectStates(liveTest, [ |
| 542 const State(Status.running, Result.success), |
| 543 const State(Status.complete, Result.error) |
| 544 ]); |
| 545 |
| 546 expectErrors(liveTest, [(error) { |
| 547 expect(lastState.status, equals(Status.complete)); |
| 548 expect(error, new isInstanceOf<TimeoutException>()); |
| 549 }]); |
| 550 |
| 551 liveTest.run(); |
| 552 async.elapse(new Duration(seconds: 15)); |
| 553 }); |
| 554 }); |
| 555 }); |
510 } | 556 } |
511 | 557 |
512 LocalTest _localTest(body(), {tearDown()}) => | 558 LocalTest _localTest(body(), {tearDown(), Metadata metadata}) { |
513 new LocalTest("test", new Metadata(), body, tearDown: tearDown); | 559 if (metadata == null) metadata = new Metadata(); |
| 560 return new LocalTest("test", metadata, body, tearDown: tearDown); |
| 561 } |
OLD | NEW |