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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 Test get test => this.group.entries.single as Test; | 57 Test get test => this.group.entries.single as Test; |
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(), {TestPlatform platform}) { | 67 factory LoadSuite(String name, body(), {String path, TestPlatform platform}) { |
68 var completer = new Completer.sync(); | 68 var completer = new Completer.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 |
(...skipping 11 matching lines...) Expand all Loading... |
89 } | 89 } |
90 }); | 90 }); |
91 | 91 |
92 // If the test is forcibly closed, exit immediately. It doesn't have any | 92 // If the test is forcibly closed, exit immediately. It doesn't have any |
93 // cleanup to do that won't be handled by Loader.close. | 93 // cleanup to do that won't be handled by Loader.close. |
94 invoker.onClose.then((_) { | 94 invoker.onClose.then((_) { |
95 if (completer.isCompleted) return; | 95 if (completer.isCompleted) return; |
96 completer.complete(); | 96 completer.complete(); |
97 invoker.removeOutstandingCallback(); | 97 invoker.removeOutstandingCallback(); |
98 }); | 98 }); |
99 }, completer.future, platform: platform); | 99 }, completer.future, path: path, platform: platform); |
100 } | 100 } |
101 | 101 |
102 /// A utility constructor for a load suite that just throws [exception]. | 102 /// A utility constructor for a load suite that just throws [exception]. |
103 /// | 103 /// |
104 /// The suite's name will be based on [exception]'s path. | 104 /// The suite's name will be based on [exception]'s path. |
105 factory LoadSuite.forLoadException(LoadException exception, | 105 factory LoadSuite.forLoadException(LoadException exception, |
106 {StackTrace stackTrace, TestPlatform platform}) { | 106 {StackTrace stackTrace, TestPlatform platform}) { |
107 if (stackTrace == null) stackTrace = new Trace.current(); | 107 if (stackTrace == null) stackTrace = new Trace.current(); |
108 | 108 |
109 return new LoadSuite("loading ${exception.path}", () { | 109 return new LoadSuite("loading ${exception.path}", () { |
110 return new Future.error(exception, stackTrace); | 110 return new Future.error(exception, stackTrace); |
111 }, platform: platform); | 111 }, path: exception.path, platform: platform); |
112 } | 112 } |
113 | 113 |
114 /// A utility constructor for a load suite that just emits [suite]. | 114 /// A utility constructor for a load suite that just emits [suite]. |
115 factory LoadSuite.forSuite(RunnerSuite suite) { | 115 factory LoadSuite.forSuite(RunnerSuite suite) { |
116 return new LoadSuite("loading ${suite.path}", () => suite, | 116 return new LoadSuite("loading ${suite.path}", () => suite, |
117 platform: suite.platform); | 117 path: suite.path, platform: suite.platform); |
118 } | 118 } |
119 | 119 |
120 LoadSuite._(String name, void body(), this._suiteAndZone, | 120 LoadSuite._(String name, void body(), this._suiteAndZone, |
121 {TestPlatform platform}) | 121 {String path, TestPlatform platform}) |
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 ]), 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, platform: old.platform); | 130 : super(old.group, path: old.path, platform: old.platform); |
131 | 131 |
132 /// Creates a new [LoadSuite] that's identical to this one, but that | 132 /// Creates a new [LoadSuite] that's identical to this one, but that |
133 /// transforms [suite] once it's loaded. | 133 /// transforms [suite] once it's loaded. |
134 /// | 134 /// |
135 /// If [suite] completes to `null`, [change] won't be run. [change] is run | 135 /// 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 | 136 /// within the load test's zone, so any errors or prints it emits will be |
137 /// associated with that test. | 137 /// associated with that test. |
138 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { | 138 LoadSuite changeSuite(RunnerSuite change(RunnerSuite suite)) { |
139 return new LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { | 139 return new LoadSuite._changeSuite(this, _suiteAndZone.then((pair) { |
140 if (pair == null) return null; | 140 if (pair == null) return null; |
(...skipping 15 matching lines...) Expand all Loading... |
156 | 156 |
157 if (liveTest.errors.isEmpty) return await suite; | 157 if (liveTest.errors.isEmpty) return await suite; |
158 | 158 |
159 var error = liveTest.errors.first; | 159 var error = liveTest.errors.first; |
160 await new Future.error(error.error, error.stackTrace); | 160 await new Future.error(error.error, error.stackTrace); |
161 throw 'unreachable'; | 161 throw 'unreachable'; |
162 } | 162 } |
163 | 163 |
164 Future close() async {} | 164 Future close() async {} |
165 } | 165 } |
OLD | NEW |