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

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

Issue 1260253005: Switch from AsyncThunk to AsyncMemoizer. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 4 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 | « no previous file | lib/src/runner/browser/compiler_pool.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; 5 library test.runner;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:async/async.dart';
11
10 import 'backend/metadata.dart'; 12 import 'backend/metadata.dart';
11 import 'backend/test_platform.dart'; 13 import 'backend/test_platform.dart';
12 import 'runner/application_exception.dart'; 14 import 'runner/application_exception.dart';
13 import 'runner/configuration.dart'; 15 import 'runner/configuration.dart';
14 import 'runner/engine.dart'; 16 import 'runner/engine.dart';
15 import 'runner/load_exception.dart'; 17 import 'runner/load_exception.dart';
16 import 'runner/load_suite.dart'; 18 import 'runner/load_suite.dart';
17 import 'runner/loader.dart'; 19 import 'runner/loader.dart';
18 import 'runner/reporter.dart'; 20 import 'runner/reporter.dart';
19 import 'runner/reporter/compact.dart'; 21 import 'runner/reporter/compact.dart';
20 import 'runner/reporter/expanded.dart'; 22 import 'runner/reporter/expanded.dart';
21 import 'runner/runner_suite.dart'; 23 import 'runner/runner_suite.dart';
22 import 'util/async_thunk.dart';
23 import 'util/io.dart'; 24 import 'util/io.dart';
24 import 'utils.dart'; 25 import 'utils.dart';
25 26
26 /// The set of platforms for which debug flags are (currently) not supported. 27 /// The set of platforms for which debug flags are (currently) not supported.
27 final _debugUnsupportedPlatforms = new Set.from( 28 final _debugUnsupportedPlatforms = new Set.from(
28 [TestPlatform.vm, TestPlatform.phantomJS, TestPlatform.contentShell]); 29 [TestPlatform.vm, TestPlatform.phantomJS, TestPlatform.contentShell]);
29 30
30 /// A class that loads and runs tests based on a [Configuration]. 31 /// A class that loads and runs tests based on a [Configuration].
31 /// 32 ///
32 /// This maintains a [Loader] and an [Engine] and passes test suites from one to 33 /// This maintains a [Loader] and an [Engine] and passes test suites from one to
33 /// the other, as well as printing out tests with a [CompactReporter] or an 34 /// the other, as well as printing out tests with a [CompactReporter] or an
34 /// [ExpandedReporter]. 35 /// [ExpandedReporter].
35 class Runner { 36 class Runner {
36 /// The configuration for the runner. 37 /// The configuration for the runner.
37 final Configuration _configuration; 38 final Configuration _configuration;
38 39
39 /// The loader that loads the test suites from the filesystem. 40 /// The loader that loads the test suites from the filesystem.
40 final Loader _loader; 41 final Loader _loader;
41 42
42 /// The engine that runs the test suites. 43 /// The engine that runs the test suites.
43 final Engine _engine; 44 final Engine _engine;
44 45
45 /// The reporter that's emitting the test runner's results. 46 /// The reporter that's emitting the test runner's results.
46 final Reporter _reporter; 47 final Reporter _reporter;
47 48
48 /// The subscription to the stream returned by [_loadSuites]. 49 /// The subscription to the stream returned by [_loadSuites].
49 StreamSubscription _suiteSubscription; 50 StreamSubscription _suiteSubscription;
50 51
51 /// The thunk for ensuring [close] only runs once. 52 /// The memoizer for ensuring [close] only runs once.
52 final _closeThunk = new AsyncThunk(); 53 final _closeMemo = new AsyncMemoizer();
53 bool get _closed => _closeThunk.hasRun; 54 bool get _closed => _closeMemo.hasRun;
54 55
55 /// Creates a new runner based on [configuration]. 56 /// Creates a new runner based on [configuration].
56 factory Runner(Configuration configuration) { 57 factory Runner(Configuration configuration) {
57 var metadata = new Metadata( 58 var metadata = new Metadata(
58 verboseTrace: configuration.verboseTrace); 59 verboseTrace: configuration.verboseTrace);
59 var loader = new Loader(configuration.platforms, 60 var loader = new Loader(configuration.platforms,
60 pubServeUrl: configuration.pubServeUrl, 61 pubServeUrl: configuration.pubServeUrl,
61 packageRoot: configuration.packageRoot, 62 packageRoot: configuration.packageRoot,
62 color: configuration.color, 63 color: configuration.color,
63 metadata: metadata, 64 metadata: metadata,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // Explicitly check "== true" here because [Engine.run] can return `null` 125 // Explicitly check "== true" here because [Engine.run] can return `null`
125 // if the engine was closed prematurely. 126 // if the engine was closed prematurely.
126 return success == true; 127 return success == true;
127 } 128 }
128 129
129 /// Closes the runner. 130 /// Closes the runner.
130 /// 131 ///
131 /// This stops any future test suites from running. It will wait for any 132 /// This stops any future test suites from running. It will wait for any
132 /// currently-running VM tests, in case they have stuff to clean up on the 133 /// currently-running VM tests, in case they have stuff to clean up on the
133 /// filesystem. 134 /// filesystem.
134 Future close() => _closeThunk.run(() async { 135 Future close() => _closeMemo.runOnce(() async {
135 var timer; 136 var timer;
136 if (!_engine.isIdle) { 137 if (!_engine.isIdle) {
137 // Wait a bit to print this message, since printing it eagerly looks weird 138 // Wait a bit to print this message, since printing it eagerly looks weird
138 // if the tests then finish immediately. 139 // if the tests then finish immediately.
139 timer = new Timer(new Duration(seconds: 1), () { 140 timer = new Timer(new Duration(seconds: 1), () {
140 // Pause the reporter while we print to ensure that we don't interfere 141 // Pause the reporter while we print to ensure that we don't interfere
141 // with its output. 142 // with its output.
142 _reporter.pause(); 143 _reporter.pause();
143 print("Waiting for current test(s) to finish."); 144 print("Waiting for current test(s) to finish.");
144 print("Press Control-C again to terminate immediately."); 145 print("Press Control-C again to terminate immediately.");
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 239
239 // TODO(nweiz): Display something in the paused browsers indicating that 240 // TODO(nweiz): Display something in the paused browsers indicating that
240 // they're paused. 241 // they're paused.
241 242
242 await stdinLines.next; 243 await stdinLines.next;
243 } finally { 244 } finally {
244 _reporter.resume(); 245 _reporter.resume();
245 } 246 }
246 } 247 }
247 } 248 }
OLDNEW
« no previous file with comments | « no previous file | lib/src/runner/browser/compiler_pool.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698