Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /// A test library for testing test libraries? We must go deeper. | 5 /// A test library for testing test libraries? We must go deeper. |
| 6 /// | 6 /// |
| 7 /// Since unit testing code tends to use a lot of global state, it can be tough | 7 /// Since unit testing code tends to use a lot of global state, it can be tough |
| 8 /// to test. This library manages it by running each test case in a child | 8 /// to test. This library manages it by running each test case in a child |
| 9 /// isolate, then reporting the results back to the parent isolate. | 9 /// isolate, then reporting the results back to the parent isolate. |
| 10 library metatest; | 10 library metatest; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 100 String _testToRun; | 100 String _testToRun; |
| 101 | 101 |
| 102 /// The port with which the child isolate should communicate with the parent | 102 /// The port with which the child isolate should communicate with the parent |
| 103 /// isolate. `null` in the parent isolate. Not set until [_inChildIsolate] | 103 /// isolate. `null` in the parent isolate. Not set until [_inChildIsolate] |
| 104 /// completes. | 104 /// completes. |
| 105 SendPort _replyTo; | 105 SendPort _replyTo; |
| 106 | 106 |
| 107 /// The cached [Future] for [_inChildIsolate]. | 107 /// The cached [Future] for [_inChildIsolate]. |
| 108 Future<bool> _inChildIsolateFuture; | 108 Future<bool> _inChildIsolateFuture; |
| 109 | 109 |
| 110 /// The initial message the isolate received. | |
|
Lasse Reichstein Nielsen
2013/10/25 09:42:49
the isolate received -> received by the isolate.
floitsch
2013/10/25 13:11:01
Done.
| |
| 111 var initialMessage; | |
| 112 | |
| 110 /// Returns whether or not we're running in a child isolate that's supposed to | 113 /// Returns whether or not we're running in a child isolate that's supposed to |
| 111 /// run a test. | 114 /// run a test. |
| 112 Future<bool> get _inChildIsolate { | 115 Future<bool> get _inChildIsolate { |
| 113 if (_inChildIsolateFuture != null) return _inChildIsolateFuture; | 116 if (_inChildIsolateFuture != null) return _inChildIsolateFuture; |
| 114 | 117 |
| 115 var completer = new Completer(); | 118 if (initialMessage == null) { |
| 116 port.receive((message, replyTo) { | 119 _inChildIsolateFuture = new Future.value(false); |
| 117 _testToRun = message['testToRun']; | 120 } else { |
| 118 _executable = message['executable']; | 121 _testToRun = initialMessage['testToRun']; |
| 119 _replyTo = replyTo; | 122 _executable = initialMessage['executable']; |
| 120 port.close(); | 123 _replyTo = initialMessage['replyTo']; |
| 121 completer.complete(true); | 124 _inChildIsolateFuture = new Future.value(true); |
| 122 }); | 125 } |
| 123 | |
| 124 // TODO(nweiz): don't use a timeout here once issue 8416 is fixed. | |
| 125 _inChildIsolateFuture = timeout(completer.future, 500, () { | |
| 126 port.close(); | |
| 127 return false; | |
| 128 }); | |
| 129 return _inChildIsolateFuture; | 126 return _inChildIsolateFuture; |
| 130 } | 127 } |
| 131 | 128 |
| 132 /// Runs the test described by [description] in its own isolate. Returns a map | 129 /// Runs the test described by [description] in its own isolate. Returns a map |
| 133 /// describing the results of that test run. | 130 /// describing the results of that test run. |
| 134 Future<Map> _runInIsolate(String description) { | 131 Future<Map> _runInIsolate(String description) { |
| 132 var replyPort = new ReceivePort(); | |
| 135 // TODO(nweiz): Don't use path here once issue 8440 is fixed. | 133 // TODO(nweiz): Don't use path here once issue 8440 is fixed. |
| 136 var future = spawnUri(path.join(path.current, Platform.script)).call({ | 134 return Isolate.spawnUri(Uri.parse(path.join(path.current, Platform.script)), |
| 135 [], { | |
| 137 'testToRun': description, | 136 'testToRun': description, |
| 138 'executable': Platform.executable | 137 'executable': Platform.executable, |
| 139 }); | 138 'replyTo': replyPort.sendPort |
| 140 // TODO(nweiz): Remove this timeout once issue 8417 is fixed and we can | 139 }).then((_) { |
| 141 // capture top-level exceptions. | 140 var future = replyPort.first; |
| 142 return timeout(future, 30 * 1000, () { | 141 |
| 143 throw 'Timed out waiting for test to complete.'; | 142 // TODO(nweiz): Remove this timeout once issue 8417 is fixed and we can |
| 143 // capture top-level exceptions. | |
| 144 return timeout(future, 30 * 1000, () { | |
| 145 throw 'Timed out waiting for test to complete.'; | |
| 146 }); | |
| 144 }); | 147 }); |
| 145 } | 148 } |
| 146 | 149 |
| 147 /// Returns whether [results] (a test result map) describes a test run in which | 150 /// Returns whether [results] (a test result map) describes a test run in which |
| 148 /// an error occurred. | 151 /// an error occurred. |
| 149 bool _hasError(Map results) { | 152 bool _hasError(Map results) { |
| 150 return results['errors'] > 0 || results['uncaughtError'] != null || | 153 return results['errors'] > 0 || results['uncaughtError'] != null || |
| 151 (results['passed'] == 0 && results['failed'] == 0); | 154 (results['passed'] == 0 && results['failed'] == 0); |
| 152 } | 155 } |
| 153 | 156 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 "uncaughtError": uncaughtError, | 216 "uncaughtError": uncaughtError, |
| 214 "results": results.map((testCase) => { | 217 "results": results.map((testCase) => { |
| 215 "description": testCase.description, | 218 "description": testCase.description, |
| 216 "message": testCase.message, | 219 "message": testCase.message, |
| 217 "result": testCase.result, | 220 "result": testCase.result, |
| 218 "stackTrace": testCase.stackTrace | 221 "stackTrace": testCase.stackTrace |
| 219 }).toList() | 222 }).toList() |
| 220 }); | 223 }); |
| 221 } | 224 } |
| 222 } | 225 } |
| OLD | NEW |