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

Unified Diff: test/single_subscription_transformer_test.dart

Issue 1584023002: Add SingleSubscriptionTransformer. (Closed) Base URL: git@github.com:dart-lang/async.git@master
Patch Set: Update pubspec Created 4 years, 11 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 | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/single_subscription_transformer_test.dart
diff --git a/test/single_subscription_transformer_test.dart b/test/single_subscription_transformer_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f21d4e9a3f6cb2420c88df9d5f659b932d3f6d5b
--- /dev/null
+++ b/test/single_subscription_transformer_test.dart
@@ -0,0 +1,50 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+
+import 'package:async/async.dart';
+import 'package:test/test.dart';
+
+import 'utils.dart';
+
+void main() {
+ test("buffers events as soon as it's bound", () async {
+ var controller = new StreamController.broadcast();
+ var stream = controller.stream.transform(
+ const SingleSubscriptionTransformer());
+
+ // Add events before [stream] has a listener to be sure it buffers them.
+ controller.add(1);
+ controller.add(2);
+ await flushMicrotasks();
+
+ expect(stream.toList(), completion(equals([1, 2, 3, 4])));
+ await flushMicrotasks();
+
+ controller.add(3);
+ controller.add(4);
+ controller.close();
+ });
+
+ test("cancels the subscription to the broadcast stream when it's canceled",
+ () async {
+ var canceled = false;
+ var controller = new StreamController.broadcast(onCancel: () {
+ canceled = true;
+ });
+ var stream = controller.stream.transform(
+ const SingleSubscriptionTransformer());
+ await flushMicrotasks();
+ expect(canceled, isFalse);
+
+ var subscription = stream.listen(null);
+ await flushMicrotasks();
+ expect(canceled, isFalse);
+
+ subscription.cancel();
+ await flushMicrotasks();
+ expect(canceled, isTrue);
+ });
+}
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698