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

Unified Diff: test/subscription_stream_test.dart

Issue 1390923006: Fix timing of async test. (Closed) Base URL: https://github.com/dart-lang/async@master
Patch Set: Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/subscription_stream_test.dart
diff --git a/test/subscription_stream_test.dart b/test/subscription_stream_test.dart
index 03f0dddec203723465beb5679edbed44f787adc9..1bf6d9980d641b6e3208dc45c919d7bc427fdf75 100644
--- a/test/subscription_stream_test.dart
+++ b/test/subscription_stream_test.dart
@@ -70,11 +70,14 @@ main() {
});
group("cancelOnError source:", () {
- for (var sourceCancels in [false, true]) {
+ for (var sourceCancels in [/*false,*/ true]) {
floitsch 2015/10/12 13:18:24 debug comment?
Lasse Reichstein Nielsen 2015/10/13 10:38:21 Yes, removed.
group("${sourceCancels ? "yes" : "no"}:", () {
var subscriptionStream;
+ var onCancel; // Completes if source stream is canceled before done.
setUp(() {
- var source = createErrorStream();
+ var cancelCompleter = new Completer();
+ var source = createErrorStream(cancelCompleter);
+ onCancel = cancelCompleter.future;
var sourceSubscription = source.listen(null,
cancelOnError: sourceCancels);
subscriptionStream = new SubscriptionStream<int>(sourceSubscription);
@@ -89,9 +92,12 @@ main() {
cancelOnError: false);
var expected = [1, 2, "To err is divine!"];
if (sourceCancels) {
- var timeout = done.future.timeout(const Duration(milliseconds: 5),
- onTimeout: () => true);
- expect(await timeout, true);
+ await onCancel;
+ // And [done] won't complete at all.
+ bool isDone = false;
+ done.future.then((_) { isDone = true; });
+ await new Future.delayed(const Duration(milliseconds: 5));
+ expect(isDone, false);
} else {
expected.add(4);
await done.future;
@@ -155,20 +161,25 @@ Stream<int> createStream() async* {
yield 4;
}
-Stream<int> createErrorStream() {
- StreamController controller = new StreamController<int>();
- () async {
- controller.add(1);
+Stream<int> createErrorStream([Completer onCancel]) async* {
+ bool canceled = true;
+ try {
+ yield 1;
await flushMicrotasks();
- controller.add(2);
+ yield 2;
await flushMicrotasks();
- controller.addError("To err is divine!");
+ yield* new Future.error("To err is divine!").asStream();
await flushMicrotasks();
- controller.add(4);
+ yield 4;
await flushMicrotasks();
- controller.close();
- }();
- return controller.stream;
+ canceled = false;
+ } finally {
+ // Completes before the "done", but should be after all events.
+ if (canceled && onCancel != null) {
+ await flushMicrotasks();
+ onCancel.complete();
+ }
+ }
}
Stream<int> createLongStream() async* {
« 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