Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #13 from alechenninger/fix-fake-async-order
Browse files Browse the repository at this point in the history
Use FIFO timer ordering in FakeAsync
  • Loading branch information
yjbanov committed Feb 24, 2016
2 parents 033ab86 + 1dcf7bf commit 309c549
Show file tree
Hide file tree
Showing 4 changed files with 630 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/testing/src/fake_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ class _FakeAsync extends FakeAsync {
if (flushPeriodicTimers) {
return _timers.isNotEmpty;
} else {
// translation: keep draining while non-periodic timers exist
return _timers.any((_FakeTimer timer) => !timer._isPeriodic);
// translation: drain every timer (periodic or not) that will occur up
// until the latest non-periodic timer
return _timers.any((_FakeTimer timer) =>
!timer._isPeriodic || timer._nextCall <= _elapsed);
}
});
}
Expand Down Expand Up @@ -234,8 +236,9 @@ class _FakeAsync extends FakeAsync {
}

_FakeTimer _getNextTimer() {
return min(_timers,
(timer1, timer2) => timer1._nextCall.compareTo(timer2._nextCall));
return _timers.isEmpty
? null
: _timers.reduce((t1, t2) => t1._nextCall <= t2._nextCall ? t1 : t2);
}

_runTimer(_FakeTimer timer) {
Expand Down
2 changes: 2 additions & 0 deletions test/all_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'future_stream_test.dart' as future_stream_test;
import 'iteration_test.dart' as iteration_test;
import 'metronome_test.dart' as metronome_test;
import 'stream_router_test.dart' as stream_router_test;
import 'testing/all_tests.dart' as testing;

main() {
countdown_timer_test.main();
Expand All @@ -28,4 +29,5 @@ main() {
iteration_test.main();
metronome_test.main();
stream_router_test.main();
testing.main();
}
19 changes: 19 additions & 0 deletions test/testing/all_tests.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'fake_async_test.dart' as fake_async_test;

main() {
fake_async_test.main();
}
Loading

0 comments on commit 309c549

Please sign in to comment.