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

Unified Diff: pkg/unittest/test/breath_test.dart

Issue 734023002: Make the unittest's breath test a bit more resilient against timing issue. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1d6325116898df7b896386ef486ee03909b2e307 100644
--- a/pkg/unittest/test/breath_test.dart
+++ b/pkg/unittest/test/breath_test.dart
@@ -16,18 +16,28 @@ void main() {
var start;
test('initial', () {
+ start = new DateTime.now().millisecondsSinceEpoch;
Timer.run(() {
sentinel = 1;
});
});
test('starve', () {
- start = new DateTime.now().millisecondsSinceEpoch;
- var now;
- do {
+ var now = new DateTime.now().millisecondsSinceEpoch;
+ while (now - start <= BREATH_INTERVAL) {
+ // If less than BREATH_INTERVAL time has passed since
+ // we scheduled the 'initial' timer it implies the
+ // current test is being run as a microtask which is
+ // again run before any timer callbacks. Hence the
+ // sentinel should not be 1.
expect(sentinel, 0);
now = new DateTime.now().millisecondsSinceEpoch;
- } while (now - start <= BREATH_INTERVAL);
+ };
+ // At this point we know at least BREATH_INTERVAL time has
+ // passed since we scheduled the Timer with the sentinel
+ // assignment. This means the next test should be scheduled
+ // using a timer as well. This ensures it will run after the
+ // timer scheduled in the 'initial' test.
kustermann 2014/11/17 12:32:02 This is not completely correct. If test 'initial'
});
test('breathed', () {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698