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

Unified Diff: tests/isolate/isolate_errors_test.dart

Issue 2555493003: Let `Isolate.errors` close on isolate exit. (Closed)
Patch Set: Created 4 years 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/isolate/isolate.dart ('K') | « sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/isolate/isolate_errors_test.dart
diff --git a/tests/isolate/isolate_errors_test.dart b/tests/isolate/isolate_errors_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..31735392a987a3623f027e55a72769374154f675
--- /dev/null
+++ b/tests/isolate/isolate_errors_test.dart
@@ -0,0 +1,91 @@
+// Copyright (c) 2016, 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.
+
+library isolate_errors;
+
+import "dart:isolate";
+import "dart:async";
+import "package:async_helper/async_helper.dart";
+import "package:expect/expect.dart";
+
+isomain(arg) {
+ if (arg is SendPort) {
+ RawReceivePort wait = new RawReceivePort();
+ wait.handler = (message) {
+ wait.close();
+ isomain(message);
+ };
+ arg.send(wait.sendPort);
+ } else {
+ throw new ArgumentError(arg);
+ }
+}
+
+manyErrorsMain(int count) {
+ for (int i = 0; i < count; i++) {
+ Timer.run(() { throw "test#$i"; });
+ }
+}
+
+main(){
+ asyncStart();
+ {
+ asyncStart();
+ Isolate.spawn(isomain, "test-1", paused: true).then((Isolate i) {
+ var errors = [];
+ i.errors.listen(null,
+ onError: (e, s) {
+ errors.add(e.toString().contains("test-1"));
+ },
+ onDone: () {
+ Expect.listEquals([true], errors);
+ asyncEnd();
+ });
+ i.resume(i.pauseCapability);
+ });
+ }
+
+ {
+ asyncStart();
+ var messageReceived = new Completer();
+ var p = new RawReceivePort()..handler = messageReceived.complete;
+ Isolate.spawn(isomain, p.sendPort).then((i) {
+ messageReceived.future.then((port) {
+ p.close();
+ // Isolate has started and is waiting for response.
+ var errors = [];
+ i.errors.listen(null,
+ onError: (e, s) {
+ errors.add(e.toString().contains("test-2"));
+ },
+ onDone: () {
+ Expect.listEquals([true], errors);
+ asyncEnd();
+ });
+ port.send("test-2");
+ });
+ });
+ }
+
+ // {
floitsch 2016/12/07 16:12:00 Reenable or remove?
+ // asyncStart();
+ // Isolate.spawn(manyErrorsMain, 5,
+ // paused: true, errorsAreFatal: false).then((i) {
+ // var errors = [];
+ // i.errors.listen(null,
+ // onError: (e, s) {
+ // print(e);
+ // errors.add(e.toString().contains("test#${errors.length}"));
+ // },
+ // onDone: () {
+ // print("done?");
+ // Expect.listEquals([true, true, true, true, true], errors);
+ // asyncEnd();
+ // });
+ // i.resume(i.pauseCapability);
+ // });
+ // }
+
+ asyncEnd();
+}
« sdk/lib/isolate/isolate.dart ('K') | « sdk/lib/isolate/isolate.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698