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