Skip to content

Commit

Permalink
Stop working around dart-lang/sdk#23497.
Browse files Browse the repository at this point in the history
R=kevmoo@google.com

Review URL: https://codereview.chromium.org//1660093002 .
  • Loading branch information
nex3 committed Feb 2, 2016
1 parent 9c1ec48 commit 3721400
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
25 changes: 9 additions & 16 deletions lib/src/backend/declarer.dart
Expand Up @@ -78,16 +78,16 @@ class Declarer {
testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform,
tags: tags));

_entries.add(new LocalTest(_prefix(name), metadata, () {
_entries.add(new LocalTest(_prefix(name), metadata, () async {
// TODO(nweiz): It might be useful to throw an error here if a test starts
// running while other tests from the same declarer are also running,
// since they might share closurized state.

// TODO(nweiz): Use async/await here once issue 23497 has been fixed in
// two stable versions.
return Invoker.current.waitForOutstandingCallbacks(() {
return _runSetUps().then((_) => body());
}).then((_) => _runTearDowns());
await Invoker.current.waitForOutstandingCallbacks(() async {
await _runSetUps();
await body();
});
await _runTearDowns();
}));
}

Expand Down Expand Up @@ -161,16 +161,9 @@ class Declarer {
///
/// If no set-up functions are declared, this returns a [Future] that
/// completes immediately.
Future _runSetUps() {
// TODO(nweiz): Use async/await here once issue 23497 has been fixed in two
// stable versions.
if (_parent != null) {
return _parent._runSetUps().then((_) {
return Future.forEach(_setUps, (setUp) => setUp());
});
}

return Future.forEach(_setUps, (setUp) => setUp());
Future _runSetUps() async {
if (_parent != null) await _parent._runSetUps();
await Future.forEach(_setUps, (setUp) => setUp());
}

/// Run the tear-up functions for this and any parent groups.
Expand Down
27 changes: 12 additions & 15 deletions lib/src/backend/invoker.dart
Expand Up @@ -178,12 +178,11 @@ class Invoker {
var zone;
var counter = new OutstandingCallbackCounter();
runZoned(() {
// TODO(nweiz): Use async/await here once issue 23497 has been fixed in
// two stable versions.
runZoned(() {
runZoned(() async {
zone = Zone.current;
_outstandingCallbackZones.add(zone);
new Future.sync(fn).then((_) => counter.removeOutstandingCallback());
await fn();
counter.removeOutstandingCallback();
}, onError: _handleError);
}, zoneValues: {
_counterKey: counter
Expand Down Expand Up @@ -260,10 +259,8 @@ class Invoker {

var outstandingCallbacksForBody = new OutstandingCallbackCounter();

// TODO(nweiz): Use async/await here once issue 23497 has been fixed in two
// stable versions.
Chain.capture(() {
runZonedWithValues(() {
runZonedWithValues(() async {
_invokerZone = Zone.current;
_outstandingCallbackZones.add(Zone.current);

Expand All @@ -276,15 +273,15 @@ class Invoker {
new Future(_test._body)
.then((_) => removeOutstandingCallback());

_outstandingCallbacks.noOutstandingCallbacks.then((_) {
if (_timeoutTimer != null) _timeoutTimer.cancel();
_controller.setState(
new State(Status.complete, liveTest.state.result));
await _outstandingCallbacks.noOutstandingCallbacks;
if (_timeoutTimer != null) _timeoutTimer.cancel();

// Use [Timer.run] here to avoid starving the DOM or other
// non-microtask events.
Timer.run(_controller.completer.complete);
});
_controller.setState(
new State(Status.complete, liveTest.state.result));

// Use [Timer.run] here to avoid starving the DOM or other
// non-microtask events.
Timer.run(_controller.completer.complete);
}, zoneValues: {
#test.invoker: this,
// Use the invoker as a key so that multiple invokers can have different
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Expand Up @@ -4,7 +4,7 @@ author: Dart Team <misc@dartlang.org>
description: A library for writing dart unit tests.
homepage: https://github.com/dart-lang/test
environment:
sdk: '>=1.11.0 <1.16.0'
sdk: '>=1.13.0 <1.16.0'
dependencies:
analyzer: '>=0.23.0 <0.28.0'
args: '>=0.12.1 <0.14.0'
Expand Down

0 comments on commit 3721400

Please sign in to comment.