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

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

Issue 366813005: Don't consider controller.addError to be a zone-crossing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add a new test. Created 6 years, 5 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 import 'package:async_helper/async_helper.dart'; 5 import 'package:async_helper/async_helper.dart';
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import 'dart:async'; 7 import 'dart:async';
8 import 'catch_errors.dart'; 8 import 'catch_errors.dart';
9 9
10 main() { 10 main() {
11 asyncStart(); 11 asyncStart();
12 Completer done = new Completer(); 12 Completer done = new Completer();
13 13
14 var events = []; 14 var events = [];
15 StreamController controller; 15 StreamController controller;
16 Stream stream; 16 Stream stream;
17 // Test that the first listen on a `asBroadcastStream` determines the 17 // Test that streams live in the zone they have been listened too.
18 // zone the subscription lives in. The inner listen happens first, and 18 // It doesn't matter how many zone-boundaries the stream traverses. What
19 // the outer listener must not see the error since it would cross a 19 // counts is the zone where `listen` was invoked.
20 // zone boundary. It is therefore given to the inner `catchErrors`.
21 catchErrors(() { 20 catchErrors(() {
22 catchErrors(() { 21 catchErrors(() {
23 controller = new StreamController(); 22 controller = new StreamController();
24 stream = controller.stream 23 stream = controller.stream
25 .map((x) { 24 .map((x) {
26 events.add("map $x"); 25 events.add("map $x");
27 return x + 100; 26 return x + 100;
28 }) 27 })
29 .asBroadcastStream(); 28 .asBroadcastStream();
30 stream 29 stream
31 .transform(new StreamTransformer.fromHandlers( 30 .transform(new StreamTransformer.fromHandlers(
32 handleError: (e, st, sink) { sink.add("error $e"); })) 31 handleError: (e, st, sink) { sink.add("error $e"); }))
33 .listen((x) { events.add("stream $x"); }); 32 .listen((x) { events.add("stream $x"); });
34 scheduleMicrotask(() { 33 scheduleMicrotask(() {
35 controller.add(1); 34 controller.add(1);
36 // Errors are not allowed to traverse boundaries, but in this case the
37 // first listener of the broadcast stream is in the same error-zone. So
38 // this should work.
39 controller.addError(2); 35 controller.addError(2);
40 controller.close(); 36 controller.close();
37 new Future.error("done");
41 }); 38 });
42 }).listen((x) { 39 }).listen((x) {
43 events.add(x); 40 events.add(x);
Lasse Reichstein Nielsen 2014/07/10 09:45:17 Consider putting a prefix on the event here, like
floitsch 2014/07/10 13:50:42 Done.
44 if (x == 2) done.complete(true); 41 if (x == "done") done.complete(true);
45 }) 42 })
46 .asFuture().then((_) { Expect.fail("Unexpected callback"); }); 43 .asFuture().then((_) { Expect.fail("Unexpected callback"); });
47 stream.listen((x) { events.add("stream2 $x"); }); 44 stream.listen((x) { events.add("stream2 $x"); });
48 }).listen((x) { events.add("outer: $x"); }, 45 }).listen((x) { events.add("outer: $x"); },
49 onDone: () { Expect.fail("Unexpected callback"); }); 46 onDone: () { Expect.fail("Unexpected callback"); });
Lasse Reichstein Nielsen 2014/07/10 09:45:17 This is darn nigh unreadable. Is there any way to
floitsch 2014/07/10 13:50:42 Should be better now.
50 47
51 done.future.whenComplete(() { 48 done.future.whenComplete(() {
52 // Give handlers time to run. 49 // Give handlers time to run.
53 Timer.run(() { 50 Timer.run(() {
54 Expect.listEquals(["map 1", 51 Expect.listEquals(["map 1",
55 "stream 101", 52 "stream 101",
Lasse Reichstein Nielsen 2014/07/10 09:45:17 Unindent (deindent? exdent?) by 1.
floitsch 2014/07/10 13:50:42 Done.
56 "stream2 101", 53 "stream2 101",
57 "stream error 2", 54 "stream error 2",
58 2, // Caught by the inner `catchErrors`. 55 "done",
56 "outer: 2",
59 ], 57 ],
60 events); 58 events);
61 asyncEnd(); 59 asyncEnd();
62 }); 60 });
63 }); 61 });
64 } 62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698