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

Side by Side Diff: lib/src/runner/loader.dart

Issue 1086213002: Support a @Timeout annotation. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: CHANGELOG + README Created 5 years, 8 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 unified diff | Download patch
« no previous file with comments | « lib/src/runner/browser/server.dart ('k') | lib/src/runner/parse_metadata.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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 library test.runner.loader; 5 library test.runner.loader;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:isolate'; 9 import 'dart:isolate';
10 10
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (!metadata.testOn.evaluate(platform, os: currentOS)) { 128 if (!metadata.testOn.evaluate(platform, os: currentOS)) {
129 return new Future.value(); 129 return new Future.value();
130 } 130 }
131 131
132 return new Future.sync(() { 132 return new Future.sync(() {
133 if (_pubServeUrl != null && !p.isWithin('test', path)) { 133 if (_pubServeUrl != null && !p.isWithin('test', path)) {
134 throw new LoadException(path, 134 throw new LoadException(path,
135 'When using "pub serve", all test files must be in test/.'); 135 'When using "pub serve", all test files must be in test/.');
136 } 136 }
137 137
138 if (platform.isBrowser) return _loadBrowserFile(path, platform); 138 if (platform == TestPlatform.vm) return _loadVmFile(path, metadata);
139 assert(platform == TestPlatform.vm); 139 assert(platform.isBrowser);
140 return _loadVmFile(path); 140 return _loadBrowserFile(path, platform, metadata);
141 }).then((suite) { 141 }).then((suite) {
142 if (suite == null) return; 142 if (suite == null) return;
143 143
144 controller.add(suite 144 controller.add(suite.filter(platform, os: currentOS));
145 .change(metadata: metadata).filter(platform, os: currentOS));
146 }).catchError(controller.addError); 145 }).catchError(controller.addError);
147 }).then((_) => controller.close()); 146 }).then((_) => controller.close());
148 147
149 return controller.stream; 148 return controller.stream;
150 } 149 }
151 150
152 /// Load the test suite at [path] in a browser. 151 /// Load the test suite at [path] in [platform].
153 Future<Suite> _loadBrowserFile(String path, TestPlatform platform) => 152 ///
153 /// [metadata] is the suite-level metadata for the test.
154 Future<Suite> _loadBrowserFile(String path, TestPlatform platform,
155 Metadata metadata) =>
154 _browserServer.then((browserServer) => 156 _browserServer.then((browserServer) =>
155 browserServer.loadSuite(path, platform)); 157 browserServer.loadSuite(path, platform, metadata));
156 158
157 /// Load the test suite at [path] in VM isolate. 159 /// Load the test suite at [path] in VM isolate.
158 Future<Suite> _loadVmFile(String path) { 160 ///
161 /// [metadata] is the suite-level metadata for the test.
162 Future<Suite> _loadVmFile(String path, Metadata metadata) {
159 var receivePort = new ReceivePort(); 163 var receivePort = new ReceivePort();
160 164
161 return new Future.sync(() { 165 return new Future.sync(() {
162 if (_pubServeUrl != null) { 166 if (_pubServeUrl != null) {
163 var url = _pubServeUrl.resolve( 167 var url = _pubServeUrl.resolve(
164 p.relative(path, from: 'test') + '.vm_test.dart'); 168 p.relative(path, from: 'test') + '.vm_test.dart');
165 return Isolate.spawnUri(url, [], {'reply': receivePort.sendPort}) 169 return Isolate.spawnUri(url, [], {
166 .then((isolate) => new IsolateWrapper(isolate, () {})) 170 'reply': receivePort.sendPort,
171 'metadata': metadata.serialize()
172 }).then((isolate) => new IsolateWrapper(isolate, () {}))
167 .catchError((error, stackTrace) { 173 .catchError((error, stackTrace) {
168 if (error is! IsolateSpawnException) throw error; 174 if (error is! IsolateSpawnException) throw error;
169 175
170 if (error.message.contains("OS Error: Connection refused")) { 176 if (error.message.contains("OS Error: Connection refused")) {
171 throw new LoadException(path, 177 throw new LoadException(path,
172 "Error getting $url: Connection refused\n" 178 "Error getting $url: Connection refused\n"
173 'Make sure "pub serve" is running.'); 179 'Make sure "pub serve" is running.');
174 } else if (error.message.contains("404 Not Found")) { 180 } else if (error.message.contains("404 Not Found")) {
175 throw new LoadException(path, 181 throw new LoadException(path,
176 "Error getting $url: 404 Not Found\n" 182 "Error getting $url: 404 Not Found\n"
177 'Make sure "pub serve" is serving the test/ directory.'); 183 'Make sure "pub serve" is serving the test/ directory.');
178 } 184 }
179 185
180 throw new LoadException(path, error); 186 throw new LoadException(path, error);
181 }); 187 });
182 } else { 188 } else {
183 return runInIsolate(''' 189 return runInIsolate('''
190 import "package:test/src/backend/metadata.dart";
184 import "package:test/src/runner/vm/isolate_listener.dart"; 191 import "package:test/src/runner/vm/isolate_listener.dart";
185 192
186 import "${p.toUri(p.absolute(path))}" as test; 193 import "${p.toUri(p.absolute(path))}" as test;
187 194
188 void main(_, Map message) { 195 void main(_, Map message) {
189 var sendPort = message['reply']; 196 var sendPort = message['reply'];
190 IsolateListener.start(sendPort, () => test.main); 197 var metadata = new Metadata.deserialize(message['metadata']);
198 IsolateListener.start(sendPort, metadata, () => test.main);
191 } 199 }
192 ''', { 200 ''', {
193 'reply': receivePort.sendPort 201 'reply': receivePort.sendPort,
202 'metadata': metadata.serialize()
194 }, packageRoot: _packageRoot); 203 }, packageRoot: _packageRoot);
195 } 204 }
196 }).catchError((error, stackTrace) { 205 }).catchError((error, stackTrace) {
197 receivePort.close(); 206 receivePort.close();
198 if (error is LoadException) throw error; 207 if (error is LoadException) throw error;
199 return new Future.error(new LoadException(path, error), stackTrace); 208 return new Future.error(new LoadException(path, error), stackTrace);
200 }).then((isolate) { 209 }).then((isolate) {
201 _isolates.add(isolate); 210 _isolates.add(isolate);
202 return receivePort.first; 211 return receivePort.first;
203 }).then((response) { 212 }).then((response) {
204 if (response["type"] == "loadException") { 213 if (response["type"] == "loadException") {
205 return new Future.error(new LoadException(path, response["message"])); 214 return new Future.error(new LoadException(path, response["message"]));
206 } else if (response["type"] == "error") { 215 } else if (response["type"] == "error") {
207 var asyncError = RemoteException.deserialize(response["error"]); 216 var asyncError = RemoteException.deserialize(response["error"]);
208 return new Future.error( 217 return new Future.error(
209 new LoadException(path, asyncError.error), 218 new LoadException(path, asyncError.error),
210 asyncError.stackTrace); 219 asyncError.stackTrace);
211 } 220 }
212 221
213 return new Suite(response["tests"].map((test) { 222 return new Suite(response["tests"].map((test) {
214 var metadata = new Metadata.deserialize(test['metadata']); 223 var testMetadata = new Metadata.deserialize(test['metadata']);
215 return new IsolateTest(test['name'], metadata, test['sendPort']); 224 return new IsolateTest(test['name'], testMetadata, test['sendPort']);
216 }), path: path, platform: "VM"); 225 }), metadata: metadata, path: path, platform: "VM");
217 }); 226 });
218 } 227 }
219 228
220 /// Closes the loader and releases all resources allocated by it. 229 /// Closes the loader and releases all resources allocated by it.
221 Future close() { 230 Future close() {
222 for (var isolate in _isolates) { 231 for (var isolate in _isolates) {
223 isolate.kill(); 232 isolate.kill();
224 } 233 }
225 _isolates.clear(); 234 _isolates.clear();
226 235
227 if (_browserServerCompleter == null) return new Future.value(); 236 if (_browserServerCompleter == null) return new Future.value();
228 return _browserServer.then((browserServer) => browserServer.close()); 237 return _browserServer.then((browserServer) => browserServer.close());
229 } 238 }
230 } 239 }
OLDNEW
« no previous file with comments | « lib/src/runner/browser/server.dart ('k') | lib/src/runner/parse_metadata.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698