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

Side by Side Diff: tests/lib_strong/async/catch_errors27_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) 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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:async_helper/async_helper.dart';
6 import "package:expect/expect.dart";
7 import 'dart:async';
8 import 'catch_errors.dart';
9
10 main() {
11 asyncStart();
12 Completer done = new Completer();
13
14 var events = [];
15 StreamController controller;
16 Stream stream;
17 // Test that streams live in the zone they have been listened too.
18 // It doesn't matter how many zone-boundaries the stream traverses. What
19 // counts is the zone where `listen` was invoked.
20 catchErrors(() {
21 catchErrors(() {
22 controller = new StreamController();
23
24 // Assignment to "global" `stream`.
25 stream = controller.stream
26 .map((x) {
27 events.add("map $x");
28 return x + 100;
29 })
30 .asBroadcastStream();
31
32 // Consume stream in the nested zone.
33 stream
34 .transform(new StreamTransformer.fromHandlers(
35 handleError: (e, st, sink) { sink.add("error $e"); }))
36 .listen((x) { events.add("stream $x"); });
37
38 // Feed the controller in the nested zone.
39 scheduleMicrotask(() {
40 controller.add(1);
41 controller.addError(2);
42 controller.close();
43 new Future.error("done");
44 });
45
46 }).listen((x) {
47 events.add("listen: $x");
48 if (x == "done") done.complete(true);
49 })
50 .asFuture().then((_) { Expect.fail("Unexpected callback"); });
51
52 // Listen to stream in outer zone.
53 stream.listen((x) { events.add("stream2 $x"); });
54 }).listen((x) { events.add("outer: $x"); },
55 onDone: () { Expect.fail("Unexpected callback"); });
56
57 done.future.whenComplete(() {
58 // Give handlers time to run.
59 Timer.run(() {
60 Expect.listEquals(["map 1",
61 "stream 101",
62 "stream2 101",
63 "stream error 2",
64 "listen: done",
65 "outer: 2",
66 ],
67 events);
68 asyncEnd();
69 });
70 });
71 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/catch_errors26_test.dart ('k') | tests/lib_strong/async/catch_errors28_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698