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

Unified 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: Remove zone from completer. 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/async/future_impl.dart ('K') | « sdk/lib/async/future_impl.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/async_catch_errors_test.dart
diff --git a/tests/standalone/io/async_catch_errors_test.dart b/tests/standalone/io/async_catch_errors_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3acdb668b59adde055cc33526f246e892f7c4b5b
--- /dev/null
+++ b/tests/standalone/io/async_catch_errors_test.dart
@@ -0,0 +1,85 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "package:expect/expect.dart";
+import 'dart:async';
+import 'dart:isolate';
+import 'dart:io';
+
+Stream catchErrors(void body()) {
Lasse Reichstein Nielsen 2013/07/05 19:00:07 As Anders pointed out: This function is not used.
floitsch 2013/07/08 10:45:51 Done.
+ StreamController controller;
+
+ bool onError(e) {
+ controller.add(e);
+ return true;
+ }
+
+ void onDone() {
+ controller.close();
+ }
+
+ void onListen() {
+ runZonedExperimental(body, onError: onError, onDone: onDone);
+ }
+
+ controller = new StreamController(onListen: onListen);
+ return controller.stream;
+}
+
+var timeOutPort;
+
+void startTests() {
Lasse Reichstein Nielsen 2013/07/05 19:00:07 Could you move the boilerplate code below main, so
floitsch 2013/07/08 10:45:51 Done.
+ // We keep a ReceivePort open until all tests are done. This way the VM will
+ // hang if the callbacks are not invoked and the test will time out.
+ timeOutPort = new ReceivePort();
+}
+
+void finishTests() {
+ Expect.listEquals(["SocketException",
+ "FileException"],
+ events);
Lasse Reichstein Nielsen 2013/07/05 19:00:07 Indentation is off by one.
floitsch 2013/07/08 10:45:51 Done.
+ timeOutPort.close();
+}
+
+void launchNextTest() {
+ if (tests.isEmpty) {
+ finishTests();
+ return;
+ }
+ var test = tests.last;
Lasse Reichstein Nielsen 2013/07/05 19:00:07 removeLast() ?
floitsch 2013/07/08 10:45:51 Using iterator now.
+ tests.length--;
+ test();
+}
+
+void testSocketException() {
+ runZonedExperimental(() {
+ Socket.connect("4", 1).then((Socket s) {
+ Expect.fail("Socket should not be able to connect");
+ });
+ }, onError: (err) {
+ if (err is! SocketException) Expect.fail("Not expected error: $err");
+ events.add("SocketException");
+ launchNextTest();
+ });
+}
+
+void testFileException() {
+ runZonedExperimental(() {
+ new File("lol it's not a file\n").openRead().listen(null);
+ }, onError: (err) {
+ if (err is! FileException) Expect.fail("Not expected error: $err");
+ events.add("FileException");
+ launchNextTest();
+ });
Lasse Reichstein Nielsen 2013/07/05 19:00:07 Could you return a Future that completes when you
floitsch 2013/07/08 10:45:51 Done.
+}
+
+var events = [];
+// In reverse order:
Lasse Reichstein Nielsen 2013/07/05 19:00:07 Consider using a new Queue.from(your list) and use
floitsch 2013/07/08 10:45:51 Changed to iterator and then to futures.
+var tests = [testFileException, testSocketException];
+
+
+main() {
+ startTests();
+ launchNextTest();
+}
« 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