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

Side by Side Diff: tests/lib/async/stream_controller_async_test.dart

Issue 23444026: Make async stream test less flaky. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // Test the basic StreamController and StreamController.singleSubscription. 5 // Test the basic StreamController and StreamController.singleSubscription.
6 library stream_controller_async_test; 6 library stream_controller_async_test;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 var done = expectAsync0((){}); 632 var done = expectAsync0((){});
633 var c = broadcast ? new StreamController.broadcast(sync: sync) 633 var c = broadcast ? new StreamController.broadcast(sync: sync)
634 : new StreamController(sync: sync); 634 : new StreamController(sync: sync);
635 var expected = new Events() 635 var expected = new Events()
636 ..add(42)..error("error") 636 ..add(42)..error("error")
637 ..add(1)..add(2)..add(3) 637 ..add(1)..add(2)..add(3)
638 ..add(4)..add(5)..add(43)..close(); 638 ..add(4)..add(5)..add(43)..close();
639 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream; 639 var stream = asBroadcast ? c.stream.asBroadcastStream() : c.stream;
640 var actual = new Events(); 640 var actual = new Events();
641 var sub; 641 var sub;
642 var pauseIsDone = false;
642 sub = stream.listen( 643 sub = stream.listen(
643 (v) { 644 (v) {
644 if (v == 3) { 645 if (v == 3) {
645 sub.pause(new Future.delayed(const Duration(milliseconds: 15), 646 sub.pause(new Future.delayed(const Duration(milliseconds: 15),
646 () => null)); 647 () { pauseIsDone = true; }));
647 } 648 }
648 actual.add(v); 649 actual.add(v);
649 }, 650 },
650 onError: actual.error, 651 onError: actual.error,
651 onDone: actual.close); 652 onDone: actual.close);
652 var sink = c.sink; 653 var sink = c.sink;
653 sink.add(42); 654 sink.add(42);
654 sink.addError("error"); 655 sink.addError("error");
655 sink.addStream(new Stream.fromIterable([1, 2, 3, 4, 5])) 656 sink.addStream(new Stream.fromIterable([1, 2, 3, 4, 5]))
656 .then((_) { 657 .then((_) {
657 sink.add(43); 658 sink.add(43);
658 return sink.close(); 659 return sink.close();
659 }) 660 })
660 .then((_) { 661 .then((_) {
kustermann 2013/08/30 13:49:49 If you have these callbacks here, don't you have t
floitsch 2013/08/30 15:23:06 No. The `done` above makes sure that the framework
661 if (asBroadcast) { 662 if (asBroadcast) {
662 // The done-future of the sink completes when it passes 663 // The done-future of the sink completes when it passes
663 // the done event to the asBroadcastStream controller, which is 664 // the done event to the asBroadcastStream controller, which is
664 // before the final listener gets the event. 665 // before the final listener gets the event.
665 // Wait for the pause to end before testing the events. 666 // Wait for the pause to end before testing the events.
666 return new Future.delayed(const Duration(milliseconds: 50), () { 667 dynamic executeWhenPauseIsDone(Function f) {
668 if (!pauseIsDone) {
669 return new Future.delayed(const Duration(milliseconds: 50), () {
670 return executeWhenPauseIsDone(f);
671 });
672 }
673 return f();
674 }
675 return executeWhenPauseIsDone(() {
667 Expect.listEquals(expected.events, actual.events); 676 Expect.listEquals(expected.events, actual.events);
668 done(); 677 done();
669 }); 678 });
670 } else { 679 } else {
671 Expect.listEquals(expected.events, actual.events); 680 Expect.listEquals(expected.events, actual.events);
672 done(); 681 done();
673 } 682 }
674 }); 683 });
675 }); 684 });
676 } 685 }
677 686
678 main() { 687 main() {
679 testController(); 688 testController();
680 testSingleController(); 689 testSingleController();
681 testExtraMethods(); 690 testExtraMethods();
682 testPause(); 691 testPause();
683 testRethrow(); 692 testRethrow();
684 testBroadcastController(); 693 testBroadcastController();
685 testAsBroadcast(); 694 testAsBroadcast();
686 testSink(sync: true, broadcast: false, asBroadcast: false); 695 testSink(sync: true, broadcast: false, asBroadcast: false);
687 testSink(sync: true, broadcast: false, asBroadcast: true); 696 testSink(sync: true, broadcast: false, asBroadcast: true);
688 testSink(sync: true, broadcast: true, asBroadcast: false); 697 testSink(sync: true, broadcast: true, asBroadcast: false);
689 testSink(sync: false, broadcast: false, asBroadcast: false); 698 testSink(sync: false, broadcast: false, asBroadcast: false);
690 testSink(sync: false, broadcast: false, asBroadcast: true); 699 testSink(sync: false, broadcast: false, asBroadcast: true);
691 testSink(sync: false, broadcast: true, asBroadcast: false); 700 testSink(sync: false, broadcast: true, asBroadcast: false);
692 } 701 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698