Chromium Code Reviews| Index: pkg/unittest/test/breath_test.dart |
| diff --git a/pkg/unittest/test/breath_test.dart b/pkg/unittest/test/breath_test.dart |
| index 23eec84b1dde14692eae6ce6a6665dee7414d996..f96279711754e50cf86dcd278be318c731b77578 100644 |
| --- a/pkg/unittest/test/breath_test.dart |
| +++ b/pkg/unittest/test/breath_test.dart |
| @@ -11,9 +11,16 @@ import 'package:unittest/unittest.dart'; |
| void main() { |
| // Test the sync test 'breath' feature of unittest. |
| + // We use the testStartStopwatch to determine if the 'starve' |
| + // test was executed within a small enough time interval from |
| + // the first test that we are guaranteed the second test is |
| + // running in a microtask. If the second test is running as a |
| + // microtask we are guaranteed the timer scheduled in the |
| + // first test has not been run yet. |
| + var testStartStopwatch = new Stopwatch()..start(); |
| + |
| group('breath', () { |
| var sentinel = 0; |
| - var start; |
| test('initial', () { |
| Timer.run(() { |
| @@ -22,12 +29,18 @@ void main() { |
| }); |
| test('starve', () { |
| - start = new DateTime.now().millisecondsSinceEpoch; |
| - var now; |
| - do { |
| + // If less than BREATH_INTERVAL time has passed since before |
| + // we started the test group then the previous test's timer |
| + // has not been run (at least this is what we are testing). |
| + if (testStartStopwatch.elapsed <= BREATH_INTERVAL) |
|
Søren Gjesse
2014/11/17 13:20:08
Please add {}'s to the if.
I guess there are no w
|
| expect(sentinel, 0); |
| - now = new DateTime.now().millisecondsSinceEpoch; |
| - } while (now - start <= BREATH_INTERVAL); |
| + |
| + // Next we wait for at least BREATH_INTERVAL to guaranteed the |
| + // next (third) test is run using a timer which means it will |
| + // run after the timer scheduled in the first test and hence |
| + // the sentinel should have been set to 1. |
| + var sw = new Stopwatch()..start(); |
| + while (sw.elapsed < BREATH_INTERVAL); |
| }); |
| test('breathed', () { |