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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import 'package:stack_trace/stack_trace.dart'; | 7 import 'package:stack_trace/stack_trace.dart'; |
8 | 8 |
9 import '../../test.dart'; | 9 import '../../test.dart'; |
10 import '../backend/group.dart'; | 10 import '../backend/group.dart'; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 /// Creates a load suite named [name] on [platform]. | 59 /// Creates a load suite named [name] on [platform]. |
60 /// | 60 /// |
61 /// [body] may return either a [RunnerSuite] or a [Future] that completes to a | 61 /// [body] may return either a [RunnerSuite] or a [Future] that completes to a |
62 /// [RunnerSuite]. Its return value is forwarded through [suite], although if | 62 /// [RunnerSuite]. Its return value is forwarded through [suite], although if |
63 /// it throws an error that will be forwarded through the suite's test. | 63 /// it throws an error that will be forwarded through the suite's test. |
64 /// | 64 /// |
65 /// If the the load test is closed before [body] is complete, it will close | 65 /// If the the load test is closed before [body] is complete, it will close |
66 /// the suite returned by [body] once it completes. | 66 /// the suite returned by [body] once it completes. |
67 factory LoadSuite(String name, body(), {String path, TestPlatform platform}) { | 67 factory LoadSuite(String name, body(), {String path, TestPlatform platform}) { |
68 var completer = new Completer.sync(); | 68 var completer = new Completer<Pair<RunnerSuite, Zone>>.sync(); |
69 return new LoadSuite._(name, () { | 69 return new LoadSuite._(name, () { |
70 var invoker = Invoker.current; | 70 var invoker = Invoker.current; |
71 invoker.addOutstandingCallback(); | 71 invoker.addOutstandingCallback(); |
72 | 72 |
73 invoke(() async { | 73 invoke(() async { |
74 try { | 74 try { |
75 var suite = await body(); | 75 var suite = await body(); |
76 if (completer.isCompleted) { | 76 if (completer.isCompleted) { |
77 // If the load test has already been closed, close the suite it | 77 // If the load test has already been closed, close the suite it |
78 // generated. | 78 // generated. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 : super(new Group.root([ | 122 : super(new Group.root([ |
123 new LocalTest(name, | 123 new LocalTest(name, |
124 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), | 124 new Metadata(timeout: new Timeout(new Duration(minutes: 5))), |
125 body) | 125 body) |
126 ]), path: path, platform: platform); | 126 ]), path: path, platform: platform); |
127 | 127 |
128 /// A constructor used by [changeSuite]. | 128 /// A constructor used by [changeSuite]. |
129 LoadSuite._changeSuite(LoadSuite old, this._suiteAndZone) | 129 LoadSuite._changeSuite(LoadSuite old, this._suiteAndZone) |
130 : super(old.group, path: old.path, platform: old.platform); | 130 : super(old.group, path: old.path, platform: old.platform); |
131 | 131 |
| 132 /// A constructor used by [filter]. |
| 133 LoadSuite._filtered(LoadSuite old, Group filtered) |
| 134 : _suiteAndZone = old._suiteAndZone, |
| 135 super(old.group, path: old.path, platform: old.platform); |
| 136 |
132 /// Creates a new [LoadSuite] that's identical to this one, but that | 137 /// Creates a new [LoadSuite] that's identical to this one, but that |
133 /// transforms [suite] once it's loaded. | 138 /// transforms [suite] once it's loaded. |
134 /// | 139 /// |
135 /// If [suite] completes to `null`, [change] won't be run. [change] is run | 140 /// If [suite] completes to `null`, [change] won't be run. [change] is run |
136 /// within the load test's zone, so any errors or prints it emits will be | 141 /// within the load test's zone, so any errors or prints it emits will be |
137 /// associated with that test. | 142 /// associated with that test. |
138 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { | 143 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { |
139 return new LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { | 144 return new LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { |
140 if (pair == null) return null; | 145 if (pair == null) return null; |
141 | 146 |
(...skipping 12 matching lines...) Expand all Loading... |
154 liveTest.onPrint.listen(print); | 159 liveTest.onPrint.listen(print); |
155 await liveTest.run(); | 160 await liveTest.run(); |
156 | 161 |
157 if (liveTest.errors.isEmpty) return await suite; | 162 if (liveTest.errors.isEmpty) return await suite; |
158 | 163 |
159 var error = liveTest.errors.first; | 164 var error = liveTest.errors.first; |
160 await new Future.error(error.error, error.stackTrace); | 165 await new Future.error(error.error, error.stackTrace); |
161 throw 'unreachable'; | 166 throw 'unreachable'; |
162 } | 167 } |
163 | 168 |
| 169 LoadSuite filter(bool callback(Test test)) { |
| 170 var filtered = this.group.filter(callback); |
| 171 if (filtered == null) filtered = new Group.root([], metadata: metadata); |
| 172 return new LoadSuite._filtered(this, filtered); |
| 173 } |
| 174 |
164 Future close() async {} | 175 Future close() async {} |
165 } | 176 } |
OLD | NEW |