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

Unified Diff: lib/src/vm_listener.dart

Issue 914963003: Add a VmListener and IsolateTest class for running tests in other isolates. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 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/remote_exception.dart ('k') | test/invoker_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/vm_listener.dart
diff --git a/lib/src/vm_listener.dart b/lib/src/vm_listener.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7deb0b42eb52be1e943af0456317959a28420f31
--- /dev/null
+++ b/lib/src/vm_listener.dart
@@ -0,0 +1,75 @@
+// Copyright (c) 2015, 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 unittest.vm_listener;
+
+import 'dart:isolate';
+import 'dart:async';
+
+import 'declarer.dart';
+import 'remote_exception.dart';
+import 'suite.dart';
+import 'test.dart';
+
+/// A class that runs tests in a separate isolate and communicates the results
+/// back to the main isolate.
+class VmListener {
+ /// The test suite to run.
+ final Suite _suite;
+
+ /// Extracts metadata about all the tests in [main] and sends information
+ /// about them over [sendPort].
+ ///
+ /// Once that's done, this starts listening for commands about which tests to
+ /// run.
+ static void start(SendPort sendPort, main()) {
+ var declarer = new Declarer();
+ runZoned(main, zoneValues: {#unittest.declarer: declarer});
+ new VmListener._(new Suite("VmListener", declarer.tests))
+ ._listen(sendPort);
+ }
+
+ VmListener._(this._suite);
+
+ /// Send information about [_suite] across [sendPort] and start listening for
+ /// commands to run the tests.
+ void _listen(SendPort sendPort) {
+ var tests = [];
+ for (var i = 0; i < _suite.tests.length; i++) {
+ var test = _suite.tests[i];
+ var receivePort = new ReceivePort();
+ tests.add({"name": test.name, "sendPort": receivePort.sendPort});
+
+ receivePort.listen((message) {
+ assert(message['command'] == 'run');
+ _runTest(test, message['reply']);
+ });
+ }
+
+ sendPort.send(tests);
+ }
+
+ /// Runs [test] and send the results across [sendPort].
+ void _runTest(Test test, SendPort sendPort) {
+ var liveTest = test.load(_suite);
+
+ liveTest.onStateChange.listen((state) {
+ sendPort.send({
+ "type": "state-change",
+ "status": state.status.name,
+ "result": state.result.name
+ });
+ });
+
+ liveTest.onError.listen((asyncError) {
+ sendPort.send({
+ "type": "error",
+ "error": RemoteException.serialize(
+ asyncError.error, asyncError.stackTrace)
+ });
+ });
+
+ liveTest.run().then((_) => sendPort.send({"type": "complete"}));
+ }
+}
« no previous file with comments | « lib/src/remote_exception.dart ('k') | test/invoker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698