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

Side by Side Diff: tests/lib_strong/async/catch_errors23_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 errors are not traversing zone boundaries.
18 // Note that the first listener of `asBroadcastStream` determines in which
19 // zone the subscription lives.
20 catchErrors(() {
21 catchErrors(() {
22 controller = new StreamController();
23
24 // Assign to "global" `stream`.
25 stream = controller.stream
26 .map((x) {
27 events.add("map $x");
28 return x + 100;
29 })
30 .transform(new StreamTransformer.fromHandlers(
31 handleError: (e, st, sink) { sink.add("error $e"); }))
32 .asBroadcastStream();
33
34 // Listen to `stream` in the inner zone.
35 stream.listen((x) { events.add("stream $x"); });
36 }).listen((x) { events.add(x); })
37 .asFuture().then((_) { Expect.fail("Unexpected callback"); });
38
39 // Listen to `stream` in the outer zone.
40 stream.listen((x) { events.add("stream2 $x"); });
41
42 // Feed the controller from the outer zone.
43 controller.add(1);
44 // `addError` does not count as zone-traversal. It should be caught by
45 // the inner error handler.
46 controller.addError("inner error");
47 new Future.error("caught by outer");
48 controller.close();
49 }).listen((x) {
50 events.add("outer: $x");
51 if (x == "caught by outer") done.complete(true);
52 },
53 onDone: () { Expect.fail("Unexpected callback"); });
54
55 done.future.whenComplete(() {
56 // Give handlers time to run.
57 Timer.run(() {
58 Expect.listEquals(["map 1",
59 "stream 101",
60 "stream2 101",
61 "stream error inner error",
62 "stream2 error inner error",
63 "outer: caught by outer",
64 ],
65 events);
66 asyncEnd();
67 });
68 });
69 }
OLDNEW
« no previous file with comments | « tests/lib_strong/async/catch_errors22_test.dart ('k') | tests/lib_strong/async/catch_errors24_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698