| OLD | NEW |
| 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.load_suite; | 5 library test.runner.load_suite; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 | 10 |
| 11 import '../../test.dart'; | 11 import '../../test.dart'; |
| 12 import '../backend/group.dart'; | 12 import '../backend/group.dart'; |
| 13 import '../backend/invoker.dart'; | 13 import '../backend/invoker.dart'; |
| 14 import '../backend/metadata.dart'; | 14 import '../backend/metadata.dart'; |
| 15 import '../backend/suite.dart'; |
| 15 import '../backend/test.dart'; | 16 import '../backend/test.dart'; |
| 16 import '../backend/test_platform.dart'; | 17 import '../backend/test_platform.dart'; |
| 17 import '../utils.dart'; | 18 import '../utils.dart'; |
| 18 import 'load_exception.dart'; | 19 import 'load_exception.dart'; |
| 19 import 'runner_suite.dart'; | 20 import 'runner_suite.dart'; |
| 20 import 'vm/environment.dart'; | 21 import 'vm/environment.dart'; |
| 21 | 22 |
| 22 /// A [Suite] emitted by a [Loader] that provides a test-like interface for | 23 /// A [Suite] emitted by a [Loader] that provides a test-like interface for |
| 23 /// loading a test file. | 24 /// loading a test file. |
| 24 /// | 25 /// |
| 25 /// This is used to expose the current status of test loading to the user. It's | 26 /// This is used to expose the current status of test loading to the user. It's |
| 26 /// important to provide users visibility into what's taking a long time and | 27 /// important to provide users visibility into what's taking a long time and |
| 27 /// where failures occur. And since some tests may be loaded at the same time as | 28 /// where failures occur. And since some tests may be loaded at the same time as |
| 28 /// others are run, it's useful to provide that visibility in the form of a test | 29 /// others are run, it's useful to provide that visibility in the form of a test |
| 29 /// suite so that it can integrate well into the existing reporting interface | 30 /// suite so that it can integrate well into the existing reporting interface |
| 30 /// without too much extra logic. | 31 /// without too much extra logic. |
| 31 /// | 32 /// |
| 32 /// A suite is constructed with logic necessary to produce a test suite. As with | 33 /// A suite is constructed with logic necessary to produce a test suite. As with |
| 33 /// a normal test body, this logic isn't run until [LiveTest.run] is called. The | 34 /// a normal test body, this logic isn't run until [LiveTest.run] is called. The |
| 34 /// suite itself is returned by [suite] once it's avaialble, but any errors or | 35 /// suite itself is returned by [suite] once it's avaialble, but any errors or |
| 35 /// prints will be emitted through the running [LiveTest]. | 36 /// prints will be emitted through the running [LiveTest]. |
| 36 class LoadSuite extends RunnerSuite { | 37 class LoadSuite extends Suite implements RunnerSuite { |
| 38 final environment = const VMEnvironment(); |
| 39 final isDebugging = false; |
| 40 final onDebugging = new StreamController<bool>().stream; |
| 41 |
| 37 /// A future that completes to the loaded suite once the suite's test has been | 42 /// A future that completes to the loaded suite once the suite's test has been |
| 38 /// run and completed successfully. | 43 /// run and completed successfully. |
| 39 /// | 44 /// |
| 40 /// This will return `null` if the suite is unavailable for some reason (for | 45 /// This will return `null` if the suite is unavailable for some reason (for |
| 41 /// example if an error occurred while loading it). | 46 /// example if an error occurred while loading it). |
| 42 Future<RunnerSuite> get suite async => (await _suiteAndZone)?.first; | 47 Future<RunnerSuite> get suite async => (await _suiteAndZone)?.first; |
| 43 | 48 |
| 44 /// A future that completes to a pair of [suite] and the load test's [Zone]. | 49 /// A future that completes to a pair of [suite] and the load test's [Zone]. |
| 45 /// | 50 /// |
| 46 /// This will return `null` if the suite is unavailable for some reason (for | 51 /// This will return `null` if the suite is unavailable for some reason (for |
| (...skipping 23 matching lines...) Expand all Loading... |
| 70 invoke(() async { | 75 invoke(() async { |
| 71 try { | 76 try { |
| 72 var suite = await body(); | 77 var suite = await body(); |
| 73 if (completer.isCompleted) { | 78 if (completer.isCompleted) { |
| 74 // If the load test has already been closed, close the suite it | 79 // If the load test has already been closed, close the suite it |
| 75 // generated. | 80 // generated. |
| 76 suite.close(); | 81 suite.close(); |
| 77 return; | 82 return; |
| 78 } | 83 } |
| 79 | 84 |
| 80 completer.complete(new Pair(suite, Zone.current)); | 85 completer.complete( |
| 86 suite == null ? null : new Pair(suite, Zone.current)); |
| 81 invoker.removeOutstandingCallback(); | 87 invoker.removeOutstandingCallback(); |
| 82 } catch (error, stackTrace) { | 88 } catch (error, stackTrace) { |
| 83 registerException(error, stackTrace); | 89 registerException(error, stackTrace); |
| 84 if (!completer.isCompleted) completer.complete(); | 90 if (!completer.isCompleted) completer.complete(); |
| 85 } | 91 } |
| 86 }); | 92 }); |
| 87 | 93 |
| 88 // If the test is forcibly closed, exit immediately. It doesn't have any | 94 // If the test is forcibly closed, exit immediately. It doesn't have any |
| 89 // cleanup to do that won't be handled by Loader.close. | 95 // cleanup to do that won't be handled by Loader.close. |
| 90 invoker.onClose.then((_) { | 96 invoker.onClose.then((_) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 108 } | 114 } |
| 109 | 115 |
| 110 /// A utility constructor for a load suite that just emits [suite]. | 116 /// A utility constructor for a load suite that just emits [suite]. |
| 111 factory LoadSuite.forSuite(RunnerSuite suite) { | 117 factory LoadSuite.forSuite(RunnerSuite suite) { |
| 112 return new LoadSuite("loading ${suite.path}", () => suite, | 118 return new LoadSuite("loading ${suite.path}", () => suite, |
| 113 platform: suite.platform); | 119 platform: suite.platform); |
| 114 } | 120 } |
| 115 | 121 |
| 116 LoadSuite._(String name, void body(), this._suiteAndZone, | 122 LoadSuite._(String name, void body(), this._suiteAndZone, |
| 117 {TestPlatform platform}) | 123 {TestPlatform platform}) |
| 118 : super(const VMEnvironment(), new Group.root([ | 124 : super(new Group.root([ |
| 119 new LocalTest(name, | 125 new LocalTest(name, |
| 120 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), | 126 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), |
| 121 body) | 127 body) |
| 122 ]), platform: platform); | 128 ]), platform: platform); |
| 123 | 129 |
| 124 /// A constructor used by [changeSuite]. | 130 /// A constructor used by [changeSuite]. |
| 125 LoadSuite._changeSuite(LoadSuite old, this._suiteAndZone) | 131 LoadSuite._changeSuite(LoadSuite old, this._suiteAndZone) |
| 126 : super(const VMEnvironment(), old.group, platform: old.platform); | 132 : super(old.group, platform: old.platform); |
| 127 | 133 |
| 128 /// Creates a new [LoadSuite] that's identical to this one, but that | 134 /// Creates a new [LoadSuite] that's identical to this one, but that |
| 129 /// transforms [suite] once it's loaded. | 135 /// transforms [suite] once it's loaded. |
| 130 /// | 136 /// |
| 131 /// If [suite] completes to `null`, [change] won't be run. [change] is run | 137 /// If [suite] completes to `null`, [change] won't be run. [change] is run |
| 132 /// within the load test's zone, so any errors or prints it emits will be | 138 /// within the load test's zone, so any errors or prints it emits will be |
| 133 /// associated with that test. | 139 /// associated with that test. |
| 134 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { | 140 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { |
| 135 return new LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { | 141 return new LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { |
| 136 if (pair == null) return null; | 142 if (pair == null) return null; |
| 137 | 143 |
| 138 var zone = pair.last; | 144 var zone = pair.last; |
| 139 return new Pair(zone.runUnaryGuarded(change, pair.first), zone); | 145 var newSuite = zone.runUnaryGuarded(change, pair.first); |
| 146 return newSuite == null ? null : new Pair(newSuite, zone); |
| 140 })); | 147 })); |
| 141 } | 148 } |
| 142 | 149 |
| 143 /// Runs the test and returns the suite. | 150 /// Runs the test and returns the suite. |
| 144 /// | 151 /// |
| 145 /// Rather than emitting errors through a [LiveTest], this just pipes them | 152 /// Rather than emitting errors through a [LiveTest], this just pipes them |
| 146 /// through the return value. | 153 /// through the return value. |
| 147 Future<RunnerSuite> getSuite() async { | 154 Future<RunnerSuite> getSuite() async { |
| 148 var liveTest = await test.load(this); | 155 var liveTest = await test.load(this); |
| 149 liveTest.onPrint.listen(print); | 156 liveTest.onPrint.listen(print); |
| 150 await liveTest.run(); | 157 await liveTest.run(); |
| 151 | 158 |
| 152 if (liveTest.errors.isEmpty) return await suite; | 159 if (liveTest.errors.isEmpty) return await suite; |
| 153 | 160 |
| 154 var error = liveTest.errors.first; | 161 var error = liveTest.errors.first; |
| 155 await new Future.error(error.error, error.stackTrace); | 162 await new Future.error(error.error, error.stackTrace); |
| 156 throw 'unreachable'; | 163 throw 'unreachable'; |
| 157 } | 164 } |
| 165 |
| 166 Future close() async {} |
| 158 } | 167 } |
| OLD | NEW |