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

Unified Diff: pkg/unittest/lib/unittest.dart

Issue 20115007: Added a way to let the outer event loop run periodically so that things like (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/unittest/test/breath_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/unittest.dart
===================================================================
--- pkg/unittest/lib/unittest.dart (revision 25443)
+++ 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
@@ -646,7 +655,7 @@
void _nextTestCase() {
runAsync(() {
_currentTestCaseIndex++;
- _nextBatch();
+ _nextTest();
});
}
@@ -695,7 +704,7 @@
_config.onStart();
runAsync(() {
- _nextBatch();
+ _nextTest();
});
}
@@ -740,25 +749,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 _nextTest() {
+ if (_currentTestCaseIndex >= testCases.length) {
+ _completeTests();
+ } else {
final testCase = testCases[_currentTestCaseIndex];
var f = _guardAsync(testCase._run, null, testCase);
- if (f != null) {
- f.whenComplete(() {
+ f.whenComplete(() {
+ var now = new DateTime.now().millisecondsSinceEpoch;
+ if ((now - _lastBreath) >= BREATH_INTERVAL) {
Siggi Cherem (dart-lang) 2013/07/24 23:34:06 consider moving this test up to _nextTestCase? the
gram 2013/07/24 23:54:52 _nextTestCase first increments the counter so ther
Siggi Cherem (dart-lang) 2013/07/25 00:13:09 basically it seems strange that we do runAsync on
gram 2013/07/25 00:33:22 Done.
+ _lastBreath = now;
+ new Future(_nextTestCase);
Siggi Cherem (dart-lang) 2013/07/24 23:34:06 isn't this the same as runAsync(_nextTestCase). I
gram 2013/07/24 23:54:52 Done.
+ } else {
_nextTestCase(); // Schedule the next test.
- });
- break;
- }
- _currentTestCaseIndex++;
+ }
+ });
}
}
« no previous file with comments | « no previous file | pkg/unittest/test/breath_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698