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

Side by Side Diff: tests/standalone/io/async_catch_errors_test.dart

Issue 18788002: Let completers complete in the zone they were constructed in. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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
(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:expect/expect.dart";
6 import 'dart:async';
7 import 'dart:isolate';
8 import 'dart:io';
9
10 Stream catchErrors(void body()) {
Anders Johnsen 2013/07/05 17:10:50 This is not used.
floitsch 2013/07/08 10:45:51 Done.
11 StreamController controller;
12
13 bool onError(e) {
14 controller.add(e);
15 return true;
16 }
17
18 void onDone() {
19 controller.close();
20 }
21
22 void onListen() {
23 runZonedExperimental(body, onError: onError, onDone: onDone);
24 }
25
26 controller = new StreamController(onListen: onListen);
27 return controller.stream;
28 }
29
30 var timeOutPort;
31
32 void startTests() {
33 // We keep a ReceivePort open until all tests are done. This way the VM will
34 // hang if the callbacks are not invoked and the test will time out.
35 timeOutPort = new ReceivePort();
36 }
37
38 void finishTests() {
39 Expect.listEquals(["SocketException",
40 "FileException"],
41 events);
42 timeOutPort.close();
43 }
44
45 void launchNextTest() {
46 if (tests.isEmpty) {
47 finishTests();
48 return;
49 }
50 var test = tests.last;
Anders Johnsen 2013/07/05 17:10:50 Heh, this looks a lot like what an iterator can ;)
floitsch 2013/07/08 10:45:51 Done.
51 tests.length--;
52 test();
53 }
54
55 void testSocketException() {
56 runZonedExperimental(() {
57 Socket.connect("4", 1).then((Socket s) {
58 Expect.fail("Socket should not be able to connect");
59 });
60 }, onError: (err) {
Anders Johnsen 2013/07/05 17:10:50 Add a counter, to test for max 1.
floitsch 2013/07/08 10:45:51 Done.
61 if (err is! SocketException) Expect.fail("Not expected error: $err");
62 events.add("SocketException");
Anders Johnsen 2013/07/05 17:10:50 How is events in scope here?
Lasse Reichstein Nielsen 2013/07/05 19:00:07 Declared at top-level in the code below.
63 launchNextTest();
64 });
65 }
66
67 void testFileException() {
68 runZonedExperimental(() {
69 new File("lol it's not a file\n").openRead().listen(null);
70 }, onError: (err) {
Anders Johnsen 2013/07/05 17:10:50 Ditto as above.
floitsch 2013/07/08 10:45:51 Done.
71 if (err is! FileException) Expect.fail("Not expected error: $err");
72 events.add("FileException");
73 launchNextTest();
74 });
75 }
76
77 var events = [];
78 // In reverse order:
79 var tests = [testFileException, testSocketException];
80
81
82 main() {
83 startTests();
84 launchNextTest();
85 }
OLDNEW
« sdk/lib/async/future_impl.dart ('K') | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698