Chromium Code Reviews| Index: pkg/unittest/lib/unittest.dart |
| =================================================================== |
| --- pkg/unittest/lib/unittest.dart (revision 25450) |
| +++ pkg/unittest/lib/unittest.dart (working copy) |
| @@ -200,6 +200,12 @@ |
| final List<TestCase> testCases = new UnmodifiableListView<TestCase>(_testCases); |
| /** |
| + * Interval (in msecs) after which synchronous tests will insert an async |
| + * delay to allow DOM or other updates. |
| + */ |
| +const int BREATH_INTERVAL = 200; |
| + |
| +/** |
| * The set of tests to run can be restricted by using [solo_test] and |
| * [solo_group]. |
| * As groups can be nested we use a counter to keep track of the nest level |
| @@ -293,6 +299,9 @@ |
| String _uncaughtErrorMessage = null; |
| +/** Time since we last gave non-sync code a chance to be scheduled. */ |
| +int _lastBreath = new DateTime.now().millisecondsSinceEpoch; |
| + |
| /** Test case result strings. */ |
| // TODO(gram) we should change these constants to use a different string |
| // (so that writing 'FAIL' in the middle of a test doesn't |
| @@ -644,10 +653,8 @@ |
| /** Advance to the next test case. */ |
| void _nextTestCase() { |
| - runAsync(() { |
| - _currentTestCaseIndex++; |
| - _nextBatch(); |
| - }); |
| + _currentTestCaseIndex++; |
| + _runTest(); |
| } |
| /** |
| @@ -691,12 +698,8 @@ |
| void runTests() { |
| _ensureInitialized(false); |
| _currentTestCaseIndex = 0; |
| - |
| _config.onStart(); |
| - |
| - runAsync(() { |
| - _nextBatch(); |
| - }); |
| + _runTest(); |
|
Siggi Cherem (dart-lang)
2013/07/25 00:50:42
I think this one needs to still call runAsync?
|
| } |
| /** |
| @@ -740,25 +743,23 @@ |
| } |
| /** |
| - * Runs a batch of tests, yielding whenever an asynchronous test starts |
| - * running. Tests will resume executing when such asynchronous test calls |
| - * [done] or if it fails with an exception. |
| + * Runs the next test. |
| */ |
| -void _nextBatch() { |
| - while (true) { |
| - if (_currentTestCaseIndex >= testCases.length) { |
| - _completeTests(); |
| - break; |
| - } |
| +void _runTest() { |
| + if (_currentTestCaseIndex >= testCases.length) { |
| + _completeTests(); |
| + } else { |
| final testCase = testCases[_currentTestCaseIndex]; |
| var f = _guardAsync(testCase._run, null, testCase); |
| - if (f != null) { |
| - f.whenComplete(() { |
| - _nextTestCase(); // Schedule the next test. |
| - }); |
| - break; |
| - } |
| - _currentTestCaseIndex++; |
| + f.whenComplete(() { |
| + var now = new DateTime.now().millisecondsSinceEpoch; |
| + if ((now - _lastBreath) >= BREATH_INTERVAL) { |
| + _lastBreath = now; |
| + Timer.run(_nextTestCase); |
| + } else { |
| + runAsync(_nextTestCase); // Schedule the next test. |
| + } |
| + }); |
| } |
| } |