OLD | NEW |
| (Empty) |
1 // Copyright (c) 2015, 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 library unittest.runner.isolate_test; | |
6 | |
7 import 'dart:isolate'; | |
8 | |
9 import '../backend/live_test.dart'; | |
10 import '../backend/live_test_controller.dart'; | |
11 import '../backend/state.dart'; | |
12 import '../backend/suite.dart'; | |
13 import '../backend/test.dart'; | |
14 import '../util/remote_exception.dart'; | |
15 | |
16 /// A test in another isolate. | |
17 class IsolateTest implements Test { | |
18 final String name; | |
19 | |
20 /// The port on which to communicate with the remote test. | |
21 final SendPort _sendPort; | |
22 | |
23 IsolateTest(this.name, this._sendPort); | |
24 | |
25 /// Loads a single runnable instance of this test. | |
26 LiveTest load(Suite suite) { | |
27 var receivePort; | |
28 var controller; | |
29 controller = new LiveTestController(suite, this, () { | |
30 controller.setState(const State(Status.running, Result.success)); | |
31 | |
32 receivePort = new ReceivePort(); | |
33 _sendPort.send({ | |
34 'command': 'run', | |
35 'reply': receivePort.sendPort | |
36 }); | |
37 | |
38 receivePort.listen((message) { | |
39 if (message['type'] == 'error') { | |
40 var asyncError = RemoteException.deserialize(message['error']); | |
41 controller.addError(asyncError.error, asyncError.stackTrace); | |
42 } else if (message['type'] == 'state-change') { | |
43 controller.setState( | |
44 new State( | |
45 new Status.parse(message['status']), | |
46 new Result.parse(message['result']))); | |
47 } else { | |
48 assert(message['type'] == 'complete'); | |
49 controller.completer.complete(); | |
50 } | |
51 }); | |
52 }, onClose: () { | |
53 if (receivePort != null) receivePort.close(); | |
54 }); | |
55 return controller.liveTest; | |
56 } | |
57 } | |
OLD | NEW |