Chromium Code Reviews

Unified Diff: tests/lib/async/stream_controller_async_test.dart

Issue 15989006: Revert until Windows crash is debugged. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « sdk/lib/utf/utf_stream.dart ('k') | tests/lib/async/stream_state_helper.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/async/stream_controller_async_test.dart
diff --git a/tests/lib/async/stream_controller_async_test.dart b/tests/lib/async/stream_controller_async_test.dart
index 53be91005be249e8497bcff6447cc80b59971768..e2aab21d6da40b916a4f6d232e33b0ff1c487c7d 100644
--- a/tests/lib/async/stream_controller_async_test.dart
+++ b/tests/lib/async/stream_controller_async_test.dart
@@ -53,6 +53,28 @@ testSingleController() {
c.add(42);
});
+ test("Single-subscription StreamController subscription changes", () {
+ StreamController c = new StreamController();
+ EventSink sink = c.sink;
+ Stream stream = c.stream;
+ int counter = 0;
+ var subscription;
+ subscription = stream.listen((data) {
+ counter += data;
+ Expect.throws(() => stream.listen(null), (e) => e is StateError);
+ subscription.cancel();
+ stream.listen((data) {
+ counter += data * 10;
+ },
+ onDone: expectAsync0(() {
+ Expect.equals(1 + 20, counter);
+ }));
+ });
+ sink.add(1);
+ sink.add(2);
+ sink.close();
+ });
+
test("Single-subscription StreamController events are buffered when"
" there is no subscriber",
() {
@@ -71,6 +93,33 @@ testSingleController() {
Expect.equals(3, counter);
}));
});
+
+ // Test subscription changes while firing.
+ test("Single-subscription StreamController subscription changes while firing",
+ () {
+ StreamController c = new StreamController();
+ EventSink sink = c.sink;
+ Stream stream = c.stream;
+ int counter = 0;
+ var subscription = stream.listen(null);
+ subscription.onData(expectAsync1((data) {
+ counter += data;
+ subscription.cancel();
+ stream.listen((data) {
+ counter += 10 * data;
+ },
+ onDone: expectAsync0(() {
+ Expect.equals(1 + 20 + 30 + 40 + 50, counter);
+ }));
+ Expect.throws(() => stream.listen(null), (e) => e is StateError);
+ }));
+ sink.add(1); // seen by stream 1
+ sink.add(2); // seen by stream 10 and 100
+ sink.add(3); // -"-
+ sink.add(4); // -"-
+ sink.add(5); // seen by stream 10
+ sink.close();
+ });
}
testExtraMethods() {
@@ -429,66 +478,10 @@ testRethrow() {
testFuture("drain", (s, act) => s.drain().then(act));
}
-void testMultiplex() {
- test("multiplex-basic", () {
- StreamController<int> c = new StreamController.multiplex(
- onListen: expectAsync0(() {}),
- onCancel: expectAsync0(() {})
- );
- Stream<int> s = c.stream;
- s.listen(expectAsync1((x) { expect(x, equals(42)); }));
- c.add(42);
- c.close();
- });
-
- test("multiplex-listen-twice", () {
- StreamController<int> c = new StreamController.multiplex(
- onListen: expectAsync0(() {}),
- onCancel: expectAsync0(() {})
- );
- c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }, count: 2));
- c.add(42);
- c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
- c.add(42);
- c.close();
- });
-
- test("multiplex-listen-twice-non-overlap", () {
- StreamController<int> c = new StreamController.multiplex(
- onListen: expectAsync0(() {}, count: 2),
- onCancel: expectAsync0(() {}, count: 2)
- );
- var sub = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
- c.add(42);
- sub.cancel();
- c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
- c.add(42);
- c.close();
- });
-
- test("multiplex-individual-pause", () {
- StreamController<int> c = new StreamController.multiplex(
- onListen: expectAsync0(() {}),
- onCancel: expectAsync0(() {})
- );
- var sub1 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
- var sub2 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); },
- count: 3));
- c.add(42);
- sub1.pause();
- c.add(42);
- sub1.cancel();
- var sub3 = c.stream.listen(expectAsync1((x) { expect(x, equals(42)); }));
- c.add(42);
- c.close();
- });
-}
-
main() {
testController();
testSingleController();
testExtraMethods();
testPause();
testRethrow();
- testMultiplex();
}
« no previous file with comments | « sdk/lib/utf/utf_stream.dart ('k') | tests/lib/async/stream_state_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine