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

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

Issue 1407593002: Properly close `setUpAll` and `tearDownAll` tests. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 2 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 | pubspec.yaml » ('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.engine; 5 library test.runner.engine;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:async/async.dart' hide Result; 10 import 'package:async/async.dart' hide Result;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 final _skipped = new Set<LiveTest>(); 125 final _skipped = new Set<LiveTest>();
126 126
127 /// The set of tests that have completed and been marked as failing or error. 127 /// The set of tests that have completed and been marked as failing or error.
128 Set<LiveTest> get failed => new UnmodifiableSetView(_failed); 128 Set<LiveTest> get failed => new UnmodifiableSetView(_failed);
129 final _failed = new Set<LiveTest>(); 129 final _failed = new Set<LiveTest>();
130 130
131 /// The tests that are still running, in the order they begain running. 131 /// The tests that are still running, in the order they begain running.
132 List<LiveTest> get active => new UnmodifiableListView(_active); 132 List<LiveTest> get active => new UnmodifiableListView(_active);
133 final _active = new QueueList<LiveTest>(); 133 final _active = new QueueList<LiveTest>();
134 134
135 /// The set of tests that have completed successfully but shouldn't be
136 /// displayed by the reporter.
137 ///
138 /// This includes load tests, `setUpAll`, and `tearDownAll`.
139 final _hidden = new Set<LiveTest>();
140
135 /// The tests from [LoadSuite]s that are still running, in the order they 141 /// The tests from [LoadSuite]s that are still running, in the order they
136 /// began running. 142 /// began running.
137 /// 143 ///
138 /// This is separate from [active] because load tests aren't always surfaced. 144 /// This is separate from [active] because load tests aren't always surfaced.
139 final _activeLoadTests = new List<LiveTest>(); 145 final _activeLoadTests = new List<LiveTest>();
140 146
141 /// Whether this engine is idle—that is, not currently executing a test. 147 /// Whether this engine is idle—that is, not currently executing a test.
142 bool get isIdle => _group.isIdle; 148 bool get isIdle => _group.isIdle;
143 149
144 /// A broadcast stream that fires an event whenever [isIdle] switches from 150 /// A broadcast stream that fires an event whenever [isIdle] switches from
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 293
288 if (state.result != Result.success) { 294 if (state.result != Result.success) {
289 _passed.remove(liveTest); 295 _passed.remove(liveTest);
290 _failed.add(liveTest); 296 _failed.add(liveTest);
291 } else if (liveTest.test.metadata.skip) { 297 } else if (liveTest.test.metadata.skip) {
292 _skipped.add(liveTest); 298 _skipped.add(liveTest);
293 } else if (countSuccess) { 299 } else if (countSuccess) {
294 _passed.add(liveTest); 300 _passed.add(liveTest);
295 } else { 301 } else {
296 _liveTests.remove(liveTest); 302 _liveTests.remove(liveTest);
303 _hidden.add(liveTest);
297 } 304 }
298 }); 305 });
299 306
300 _onTestStartedController.add(liveTest); 307 _onTestStartedController.add(liveTest);
301 308
302 // First, schedule a microtask to ensure that [onTestStarted] fires before 309 // First, schedule a microtask to ensure that [onTestStarted] fires before
303 // the first [LiveTest.onStateChange] event. Once the test finishes, use 310 // the first [LiveTest.onStateChange] event. Once the test finishes, use
304 // [new Future] to do a coarse-grained event loop pump to avoid starving 311 // [new Future] to do a coarse-grained event loop pump to avoid starving
305 // non-microtask events. 312 // non-microtask events.
306 await new Future.microtask(liveTest.run); 313 await new Future.microtask(liveTest.run);
(...skipping 25 matching lines...) Expand all
332 _active.remove(liveTest); 339 _active.remove(liveTest);
333 _liveTests.remove(liveTest); 340 _liveTests.remove(liveTest);
334 341
335 if (_activeLoadTests.isNotEmpty) { 342 if (_activeLoadTests.isNotEmpty) {
336 _active.add(_activeLoadTests.last); 343 _active.add(_activeLoadTests.last);
337 _liveTests.add(_activeLoadTests.last); 344 _liveTests.add(_activeLoadTests.last);
338 } 345 }
339 } 346 }
340 347
341 // Surface the load test if it fails so that the user can see the failure. 348 // Surface the load test if it fails so that the user can see the failure.
342 if (state.result == Result.success) return; 349 if (state.result == Result.success) {
343 _failed.add(liveTest); 350 _hidden.add(liveTest);
344 _liveTests.add(liveTest); 351 } else {
352 _failed.add(liveTest);
353 _liveTests.add(liveTest);
354 }
345 }); 355 });
346 356
347 // Run the test immediately. We don't want loading to be blocked on suites 357 // Run the test immediately. We don't want loading to be blocked on suites
348 // that are already running. 358 // that are already running.
349 _onTestStartedController.add(liveTest); 359 _onTestStartedController.add(liveTest);
350 await liveTest.run(); 360 await liveTest.run();
351 361
352 return suite.suite; 362 return suite.suite;
353 } 363 }
354 364
355 /// Signals that the caller is done paying attention to test results and the 365 /// Signals that the caller is done paying attention to test results and the
356 /// engine should release any resources it has allocated. 366 /// engine should release any resources it has allocated.
357 /// 367 ///
358 /// Any actively-running tests are also closed. VM tests are allowed to finish 368 /// Any actively-running tests are also closed. VM tests are allowed to finish
359 /// running so that any modifications they've made to the filesystem can be 369 /// running so that any modifications they've made to the filesystem can be
360 /// cleaned up. 370 /// cleaned up.
361 /// 371 ///
362 /// **Note that closing the engine is not the same as closing [suiteSink].** 372 /// **Note that closing the engine is not the same as closing [suiteSink].**
363 /// Closing [suiteSink] indicates that no more input will be provided, closing 373 /// Closing [suiteSink] indicates that no more input will be provided, closing
364 /// the engine indicates that no more output should be emitted. 374 /// the engine indicates that no more output should be emitted.
365 Future close() async { 375 Future close() async {
366 _closed = true; 376 _closed = true;
367 if (_closedBeforeDone != null) _closedBeforeDone = true; 377 if (_closedBeforeDone != null) _closedBeforeDone = true;
368 _suiteController.close(); 378 _suiteController.close();
369 379
370 // Close the running tests first so that we're sure to wait for them to 380 // Close the running tests first so that we're sure to wait for them to
371 // finish before we close their suites and cause them to become unloaded. 381 // finish before we close their suites and cause them to become unloaded.
372 var allLiveTests = liveTests.toSet()..addAll(_activeLoadTests); 382 var allLiveTests = liveTests.toSet()
383 ..addAll(_activeLoadTests)
384 ..addAll(_hidden);
373 var futures = allLiveTests.map((liveTest) => liveTest.close()).toList(); 385 var futures = allLiveTests.map((liveTest) => liveTest.close()).toList();
374 386
375 // Closing the load pool will close the test suites as soon as their tests 387 // Closing the load pool will close the test suites as soon as their tests
376 // are done. For browser suites this is effectively immediate since their 388 // are done. For browser suites this is effectively immediate since their
377 // tests shut down as soon as they're closed, but for VM suites we may need 389 // tests shut down as soon as they're closed, but for VM suites we may need
378 // to wait for tearDowns or tearDownAlls to run. 390 // to wait for tearDowns or tearDownAlls to run.
379 futures.add(_loadPool.close()); 391 futures.add(_loadPool.close());
380 await Future.wait(futures, eagerError: true); 392 await Future.wait(futures, eagerError: true);
381 } 393 }
382 } 394 }
OLDNEW
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698