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

Unified Diff: lib/src/runner/vm/isolate_test.dart

Issue 1056733002: Run test tearDowns and clean up temporary directories when a signal is caught. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 9 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
« no previous file with comments | « lib/src/runner/vm/isolate_listener.dart ('k') | lib/src/util/dart.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/runner/vm/isolate_test.dart
diff --git a/lib/src/runner/vm/isolate_test.dart b/lib/src/runner/vm/isolate_test.dart
index ef73869f4a6a9d8e63d525d06a9f38814faa5dcb..61a74cc30efae9e8491efda489a67a439ef50e35 100644
--- a/lib/src/runner/vm/isolate_test.dart
+++ b/lib/src/runner/vm/isolate_test.dart
@@ -4,6 +4,7 @@
library test.runner.vm.isolate_test;
+import 'dart:async';
import 'dart:isolate';
import '../../backend/live_test.dart';
@@ -26,11 +27,18 @@ class IsolateTest implements Test {
/// Loads a single runnable instance of this test.
LiveTest load(Suite suite) {
- var receivePort;
var controller;
+
+ // We get a new send port for communicating with the live test, since
+ // [_sendPort] is only for communicating with the non-live test. This will
+ // be non-null once the test starts running.
+ var sendPortCompleter;
+
+ var receivePort;
controller = new LiveTestController(suite, this, () {
controller.setState(const State(Status.running, Result.success));
+ sendPortCompleter = new Completer();
receivePort = new ReceivePort();
_sendPort.send({
'command': 'run',
@@ -38,7 +46,9 @@ class IsolateTest implements Test {
});
receivePort.listen((message) {
- if (message['type'] == 'error') {
+ if (message['type'] == 'started') {
+ sendPortCompleter.complete(message['reply']);
+ } else if (message['type'] == 'error') {
var asyncError = RemoteException.deserialize(message['error']);
controller.addError(asyncError.error, asyncError.stackTrace);
} else if (message['type'] == 'state-change') {
@@ -53,8 +63,21 @@ class IsolateTest implements Test {
controller.completer.complete();
}
});
- }, onClose: () {
- if (receivePort != null) receivePort.close();
+ }, () {
+ // If the test has finished running, just disconnect the receive port. The
+ // Dart process won't terminate if there are any live receive ports open.
+ if (controller.completer.isCompleted) {
+ receivePort.close();
+ return;
+ }
+
+ // If the test is still running, send it a message telling it to shut down
+ // ASAP. This causes the [Invoker] to eagerly throw exceptions whenever
+ // the test touches it.
+ sendPortCompleter.future.then((sendPort) {
+ sendPort.send({'command': 'close'});
+ return controller.completer.future;
+ }).then((_) => receivePort.close());
});
return controller.liveTest;
}
« no previous file with comments | « lib/src/runner/vm/isolate_listener.dart ('k') | lib/src/util/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698