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

Side by Side Diff: lib/src/backend/invoker.dart

Issue 1660093002: Stop working around dart-lang/sdk#23497. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Increase the SDK constraint. Created 4 years, 10 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 | « lib/src/backend/declarer.dart ('k') | 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 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 '../backend/group.dart'; 9 import '../backend/group.dart';
10 import '../frontend/expect.dart'; 10 import '../frontend/expect.dart';
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 /// 171 ///
172 /// If the test times out, the *most recent* call to 172 /// If the test times out, the *most recent* call to
173 /// [waitForOutstandingCallbacks] will treat that error as occurring within 173 /// [waitForOutstandingCallbacks] will treat that error as occurring within
174 /// [fn]—that is, it will complete immediately. 174 /// [fn]—that is, it will complete immediately.
175 Future waitForOutstandingCallbacks(fn()) { 175 Future waitForOutstandingCallbacks(fn()) {
176 heartbeat(); 176 heartbeat();
177 177
178 var zone; 178 var zone;
179 var counter = new OutstandingCallbackCounter(); 179 var counter = new OutstandingCallbackCounter();
180 runZoned(() { 180 runZoned(() {
181 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in 181 runZoned(() async {
182 // two stable versions.
183 runZoned(() {
184 zone = Zone.current; 182 zone = Zone.current;
185 _outstandingCallbackZones.add(zone); 183 _outstandingCallbackZones.add(zone);
186 new Future.sync(fn).then((_) => counter.removeOutstandingCallback()); 184 await fn();
185 counter.removeOutstandingCallback();
187 }, onError: _handleError); 186 }, onError: _handleError);
188 }, zoneValues: { 187 }, zoneValues: {
189 _counterKey: counter 188 _counterKey: counter
190 }); 189 });
191 190
192 return counter.noOutstandingCallbacks.whenComplete(() { 191 return counter.noOutstandingCallbacks.whenComplete(() {
193 _outstandingCallbackZones.remove(zone); 192 _outstandingCallbackZones.remove(zone);
194 }); 193 });
195 } 194 }
196 195
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 "or the [completes] matcher when testing async code.", 252 "or the [completes] matcher when testing async code.",
254 stackTrace); 253 stackTrace);
255 } 254 }
256 255
257 /// The method that's run when the test is started. 256 /// The method that's run when the test is started.
258 void _onRun() { 257 void _onRun() {
259 _controller.setState(const State(Status.running, Result.success)); 258 _controller.setState(const State(Status.running, Result.success));
260 259
261 var outstandingCallbacksForBody = new OutstandingCallbackCounter(); 260 var outstandingCallbacksForBody = new OutstandingCallbackCounter();
262 261
263 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in two
264 // stable versions.
265 Chain.capture(() { 262 Chain.capture(() {
266 runZonedWithValues(() { 263 runZonedWithValues(() async {
267 _invokerZone = Zone.current; 264 _invokerZone = Zone.current;
268 _outstandingCallbackZones.add(Zone.current); 265 _outstandingCallbackZones.add(Zone.current);
269 266
270 // Run the test asynchronously so that the "running" state change has 267 // Run the test asynchronously so that the "running" state change has
271 // a chance to hit its event handler(s) before the test produces an 268 // a chance to hit its event handler(s) before the test produces an
272 // error. If an error is emitted before the first state change is 269 // error. If an error is emitted before the first state change is
273 // handled, we can end up with [onError] callbacks firing before the 270 // handled, we can end up with [onError] callbacks firing before the
274 // corresponding [onStateChange], which violates the timing 271 // corresponding [onStateChange], which violates the timing
275 // guarantees. 272 // guarantees.
276 new Future(_test._body) 273 new Future(_test._body)
277 .then((_) => removeOutstandingCallback()); 274 .then((_) => removeOutstandingCallback());
278 275
279 _outstandingCallbacks.noOutstandingCallbacks.then((_) { 276 await _outstandingCallbacks.noOutstandingCallbacks;
280 if (_timeoutTimer != null) _timeoutTimer.cancel(); 277 if (_timeoutTimer != null) _timeoutTimer.cancel();
281 _controller.setState(
282 new State(Status.complete, liveTest.state.result));
283 278
284 // Use [Timer.run] here to avoid starving the DOM or other 279 _controller.setState(
285 // non-microtask events. 280 new State(Status.complete, liveTest.state.result));
286 Timer.run(_controller.completer.complete); 281
287 }); 282 // Use [Timer.run] here to avoid starving the DOM or other
283 // non-microtask events.
284 Timer.run(_controller.completer.complete);
288 }, zoneValues: { 285 }, zoneValues: {
289 #test.invoker: this, 286 #test.invoker: this,
290 // Use the invoker as a key so that multiple invokers can have different 287 // Use the invoker as a key so that multiple invokers can have different
291 // outstanding callback counters at once. 288 // outstanding callback counters at once.
292 _counterKey: outstandingCallbacksForBody, 289 _counterKey: outstandingCallbacksForBody,
293 _closableKey: true 290 _closableKey: true
294 }, 291 },
295 zoneSpecification: new ZoneSpecification( 292 zoneSpecification: new ZoneSpecification(
296 print: (self, parent, zone, line) => _controller.print(line)), 293 print: (self, parent, zone, line) => _controller.print(line)),
297 onError: _handleError); 294 onError: _handleError);
298 }); 295 });
299 } 296 }
300 } 297 }
OLDNEW
« no previous file with comments | « lib/src/backend/declarer.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698