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

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

Issue 1206033004: Only load a certain number of test suites at once. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 5 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
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
11 import 'package:analyzer/analyzer.dart'; 11 import 'package:analyzer/analyzer.dart';
12 import 'package:path/path.dart' as p; 12 import 'package:path/path.dart' as p;
13 import 'package:stack_trace/stack_trace.dart'; 13 import 'package:stack_trace/stack_trace.dart';
14 14
15 import '../backend/invoker.dart'; 15 import '../backend/invoker.dart';
16 import '../backend/metadata.dart'; 16 import '../backend/metadata.dart';
17 import '../backend/suite.dart'; 17 import '../backend/suite.dart';
18 import '../backend/test_platform.dart'; 18 import '../backend/test_platform.dart';
19 import '../util/async_thunk.dart'; 19 import '../util/async_thunk.dart';
20 import '../util/dart.dart' as dart; 20 import '../util/dart.dart' as dart;
21 import '../util/io.dart'; 21 import '../util/io.dart';
22 import '../util/isolate_wrapper.dart';
23 import '../util/remote_exception.dart'; 22 import '../util/remote_exception.dart';
24 import '../utils.dart'; 23 import '../utils.dart';
25 import 'browser/server.dart'; 24 import 'browser/server.dart';
26 import 'load_exception.dart'; 25 import 'load_exception.dart';
27 import 'load_suite.dart'; 26 import 'load_suite.dart';
28 import 'parse_metadata.dart'; 27 import 'parse_metadata.dart';
29 import 'vm/isolate_test.dart'; 28 import 'vm/isolate_test.dart';
30 29
31 /// A class for finding test files and loading them into a runnable form. 30 /// A class for finding test files and loading them into a runnable form.
32 class Loader { 31 class Loader {
(...skipping 14 matching lines...) Expand all
47 final String _root; 46 final String _root;
48 47
49 /// The package root to use for loading tests. 48 /// The package root to use for loading tests.
50 final String _packageRoot; 49 final String _packageRoot;
51 50
52 /// The URL for the `pub serve` instance to use to load tests. 51 /// The URL for the `pub serve` instance to use to load tests.
53 /// 52 ///
54 /// This is `null` if tests should be loaded from the filesystem. 53 /// This is `null` if tests should be loaded from the filesystem.
55 final Uri _pubServeUrl; 54 final Uri _pubServeUrl;
56 55
57 /// All isolates that have been spun up by the loader. 56 /// All suites that have been created by the loader.
58 final _isolates = new Set<IsolateWrapper>(); 57 final _suites = new Set<Suite>();
59 58
60 /// The server that serves browser test pages. 59 /// The server that serves browser test pages.
61 /// 60 ///
62 /// This is lazily initialized the first time it's accessed. 61 /// This is lazily initialized the first time it's accessed.
63 Future<BrowserServer> get _browserServer { 62 Future<BrowserServer> get _browserServer {
64 return _browserServerThunk.run(() { 63 return _browserServerThunk.run(() {
65 return BrowserServer.start( 64 return BrowserServer.start(
66 root: _root, 65 root: _root,
67 packageRoot: _packageRoot, 66 packageRoot: _packageRoot,
68 pubServeUrl: _pubServeUrl, 67 pubServeUrl: _pubServeUrl,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 'reply': receivePort.sendPort, 232 'reply': receivePort.sendPort,
234 'metadata': metadata.serialize() 233 'metadata': metadata.serialize()
235 }, packageRoot: p.toUri(_packageRoot), checked: true); 234 }, packageRoot: p.toUri(_packageRoot), checked: true);
236 } 235 }
237 } catch (error, stackTrace) { 236 } catch (error, stackTrace) {
238 receivePort.close(); 237 receivePort.close();
239 if (error is LoadException) rethrow; 238 if (error is LoadException) rethrow;
240 await new Future.error(new LoadException(path, error), stackTrace); 239 await new Future.error(new LoadException(path, error), stackTrace);
241 } 240 }
242 241
243 _isolates.add(isolate);
244
245 var completer = new Completer(); 242 var completer = new Completer();
246 243
247 var subscription = receivePort.listen((response) { 244 var subscription = receivePort.listen((response) {
248 if (response["type"] == "print") { 245 if (response["type"] == "print") {
249 print(response["line"]); 246 print(response["line"]);
250 } else if (response["type"] == "loadException") { 247 } else if (response["type"] == "loadException") {
248 isolate.kill();
251 completer.completeError( 249 completer.completeError(
252 new LoadException(path, response["message"]), 250 new LoadException(path, response["message"]),
253 new Trace.current()); 251 new Trace.current());
254 } else if (response["type"] == "error") { 252 } else if (response["type"] == "error") {
253 isolate.kill();
255 var asyncError = RemoteException.deserialize(response["error"]); 254 var asyncError = RemoteException.deserialize(response["error"]);
256 completer.completeError( 255 completer.completeError(
257 new LoadException(path, asyncError.error), 256 new LoadException(path, asyncError.error),
258 asyncError.stackTrace); 257 asyncError.stackTrace);
259 } else { 258 } else {
260 assert(response["type"] == "success"); 259 assert(response["type"] == "success");
261 completer.complete(response["tests"]); 260 completer.complete(response["tests"]);
262 } 261 }
263 }); 262 });
264 263
265 try { 264 try {
266 return new Suite((await completer.future).map((test) { 265 var suite = new Suite((await completer.future).map((test) {
267 var testMetadata = new Metadata.deserialize(test['metadata']); 266 var testMetadata = new Metadata.deserialize(test['metadata']);
268 return new IsolateTest(test['name'], testMetadata, test['sendPort']); 267 return new IsolateTest(test['name'], testMetadata, test['sendPort']);
269 }), metadata: metadata, path: path, platform: "VM"); 268 }),
269 metadata: metadata,
270 path: path,
271 platform: "VM",
272 onClose: isolate.kill);
273 _suites.add(suite);
274 return suite;
270 } finally { 275 } finally {
271 subscription.cancel(); 276 subscription.cancel();
272 } 277 }
273 } 278 }
274 279
275 /// Closes the loader and releases all resources allocated by it. 280 /// Closes the loader and releases all resources allocated by it.
276 Future close() { 281 Future close() {
277 return _closeThunk.run(() async { 282 return _closeThunk.run(() async {
278 for (var isolate in _isolates) { 283 await Future.wait(_suites.map((suite) => suite.close()));
279 isolate.kill(); 284 _suites.clear();
280 }
281 _isolates.clear();
282 285
283 if (!_browserServerThunk.hasRun) return; 286 if (!_browserServerThunk.hasRun) return;
284 await (await _browserServer).close(); 287 await (await _browserServer).close();
285 }); 288 });
286 } 289 }
287 } 290 }
OLDNEW
« no previous file with comments | « lib/src/runner/load_suite.dart ('k') | pubspec.yaml » ('j') | test/runner/signal_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698