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

Side by Side Diff: tests/lib_strong/async/stream_empty_test.dart

Issue 2802973005: Migrate async tests to strong (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 // Test empty stream.
6 import "package:expect/expect.dart";
7 import "dart:async";
8 import 'package:async_helper/async_helper.dart';
9
10 main() {
11 asyncStart();
12 runTest().whenComplete(asyncEnd);
13 }
14
15 Future runTest() async {
16 unreachable([a,b]) { throw "UNREACHABLE"; }
17 int tick = 0;
18 ticker() { tick++; }
19
20 asyncStart();
21
22 Stream<int> s = const Stream<int>.empty(); // Is const constructor.
23 Expect.isFalse(s is Stream<String>); // Respects type parameter.
24 StreamSubscription<int> sub =
25 s.listen(unreachable, onError: unreachable, onDone: ticker);
26 Expect.isFalse(sub is StreamSubscription<String>); // Type parameter in sub.
27
28 // Doesn't do callback in response to listen.
29 Expect.equals(tick, 0);
30 await flushMicrotasks();
31 // Completes eventually.
32 Expect.equals(tick, 1);
33
34 // It's a broadcast stream - can listen twice.
35 Expect.isTrue(s.isBroadcast);
36 StreamSubscription<int> sub2 =
37 s.listen(unreachable, onError: unreachable, onDone: unreachable);
38 // respects pause.
39 sub2.pause();
40 await flushMicrotasks();
41 // respects cancel.
42 sub2.cancel();
43 await flushMicrotasks();
44 Expect.equals(tick, 1);
45 // Still not complete.
46
47 StreamSubscription<int> sub3 =
48 s.listen(unreachable, onError: unreachable, onDone: ticker);
49 // respects pause.
50 sub3.pause();
51 Expect.equals(tick, 1);
52 await flushMicrotasks();
53 // Doesn't complete while paused.
54 Expect.equals(tick, 1);
55 sub3.resume();
56 await flushMicrotasks();
57 // Now completed.
58 Expect.equals(tick, 2);
59
60 asyncEnd();
61 }
62
63 Future flushMicrotasks() => new Future.delayed(Duration.ZERO);
OLDNEW
« no previous file with comments | « tests/lib_strong/async/stream_controller_test.dart ('k') | tests/lib_strong/async/stream_event_transformed_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698