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

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

Issue 14753009: Make StreamSubscription be the active part of a stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Made tests run (mostly) Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 event/callback protocol of the stream implementations. 5 // Test the event/callback protocol of the stream implementations.
6 // Uses a non-zero timer so it fails on d8. 6 // Uses a non-zero timer so it fails on d8.
7 7
8 library stream_state_nonzero_timer_test; 8 library stream_state_nonzero_timer_test;
9 9
10 import "dart:async"; 10 import "dart:async";
11 import "../../../pkg/unittest/lib/unittest.dart"; 11 import "../../../pkg/unittest/lib/unittest.dart";
12 import "stream_state_helper.dart"; 12 import "stream_state_helper.dart";
13 13
14 const ms5 = const Duration(milliseconds: 5); 14 const ms5 = const Duration(milliseconds: 5);
15 15
16 main() { 16 main() {
17 mainTest(false); 17 mainTest(false);
18 // TODO(floitsch): reenable? 18 // TODO(floitsch): reenable?
19 // mainTest(true); 19 // mainTest(true);
20 } 20 }
21 21
22 mainTest(bool broadcast) { 22 mainTest(bool broadcast) {
23 var p = broadcast ? "BC" : "SC"; 23 var p = broadcast ? "BC" : "SC";
24 24
25 test("$p-sub-data/pause/resume/pause/resume-done", () { 25 test("$p-sub-data/pause/resume/pause/resume-done", () {
26 var t = new StreamProtocolTest(broadcast); 26 var t = new StreamProtocolTest(broadcast);
27 t..expectSubscription(true, false) 27 t..expectSubscription()
28 ..expectData(42, () { 28 ..expectData(42, () {
29 t.pause(); 29 t.pause();
30 }) 30 })
31 ..expectPause(true, () { t.resume(); }) 31 ..expectPause(() { t.resume(); })
32 ..expectPause(false, () { t.pause(); }) 32 ..expectResume(() { t.pause(); })
33 ..expectPause(true, () { t.resume(); }) 33 ..expectPause(() { t.resume(); })
34 ..expectPause(false, () { t.close(); }) 34 ..expectResume(() { t.close(); })
35 ..expectDone() 35 ..expectDone()
36 ..expectSubscription(false, false); 36 ..expectCancel();
37 t..subscribe()..add(42); 37 t..subscribe()..add(42);
38 }); 38 });
39 39
40 test("$p-sub-data/pause-done", () { 40 test("$p-sub-data/pause-done", () {
41 var t = new StreamProtocolTest(broadcast); 41 var t = new StreamProtocolTest(broadcast);
42 t..expectSubscription(true, false) 42 t..expectSubscription()
43 ..expectData(42, () { 43 ..expectData(42, () {
44 t.pause(new Future.delayed(ms5, () => null)); 44 t.pause(new Future.delayed(ms5, () => null));
45 }) 45 })
46 ..expectPause(true) 46 ..expectPause()
47 ..expectDone() 47 ..expectDone()
48 ..expectSubscription(false, false); 48 ..expectCancel();
49 // We are calling "close" while the controller is actually paused, 49 // We are calling "close" while the controller is actually paused,
50 // and it will stay paused until the pending events are sent. 50 // and it will stay paused until the pending events are sent.
51 t..subscribe()..add(42)..close(); 51 t..subscribe()..add(42)..close();
52 }); 52 });
53 53
54 test("$p-sub-data/pause-resume/done", () { 54 test("$p-sub-data/pause-resume/done", () {
55 var t = new StreamProtocolTest(broadcast); 55 var t = new StreamProtocolTest(broadcast);
56 t..expectSubscription(true, false) 56 t..expectSubscription()
57 ..expectData(42, () { 57 ..expectData(42, () {
58 t.pause(new Future.delayed(ms5, () => null)); 58 t.pause(new Future.delayed(ms5, () => null));
59 }) 59 })
60 ..expectPause(true) 60 ..expectPause()
61 ..expectPause(false, () { t.close(); }) 61 ..expectResume(t.close)
62 ..expectDone() 62 ..expectDone()
63 ..expectSubscription(false, false); 63 ..expectCancel();
64 t..subscribe()..add(42); 64 t..subscribe()..add(42);
65 }); 65 });
66 66
67 test("$p-sub-data/data+pause-data-resume-done", () { 67 test("$p-sub-data/data+pause-data-resume-done", () {
68 var t = new StreamProtocolTest(broadcast); 68 var t = new StreamProtocolTest(broadcast);
69 t..expectSubscription(true, false) 69 t..expectSubscription()
70 ..expectData(42, () { 70 ..expectData(42, () {
71 t.add(43); 71 t.add(43);
72 t.pause(new Future.delayed(ms5, () => null)); 72 t.pause(new Future.delayed(ms5, () => null));
73 // Should now be paused until the future finishes. 73 // Should now be paused until the future finishes.
74 // After that, the controller stays paused until the pending queue 74 // After that, the controller stays paused until the pending queue
75 // is empty. 75 // is empty.
76 }) 76 })
77 ..expectPause(true) 77 ..expectPause()
78 ..expectData(43) 78 ..expectData(43)
79 ..expectPause(false, () { t.close(); }) 79 ..expectResume(t.close)
80 ..expectDone() 80 ..expectDone()
81 ..expectSubscription(false, false); 81 ..expectCancel();
82 t..subscribe()..add(42); 82 t..subscribe()..add(42);
83 }); 83 });
84 84 return;
floitsch 2013/05/23 18:38:23 spurious 'return'.
85 test("$p-pause-during-callback", () { 85 test("$p-pause-during-callback", () {
86 var t = new StreamProtocolTest(broadcast); 86 var t = new StreamProtocolTest(broadcast);
87 t..expectSubscription(true, false) 87 t..expectSubscription()
88 ..expectData(42, () { 88 ..expectData(42, () {
89 t.pause(); 89 t.pause();
90 }) 90 })
91 ..expectPause(true, () { 91 ..expectPause(() {
92 t.resume(); 92 t.resume();
93 }) 93 })
94 ..expectPause(false, () { 94 ..expectResume(() {
95 t.pause(); 95 t.pause();
96 t.resume(); 96 t.resume();
97 t.close(); 97 t.close();
98 }) 98 })
99 ..expectDone() 99 ..expectDone()
100 ..expectSubscription(false, false); 100 ..expectCancel();
101 t..subscribe() 101 t..subscribe()
102 ..add(42); 102 ..add(42);
103 }); 103 });
104 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698