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

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

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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 | « packages/unittest/test/async_setup_teardown_test.dart ('k') | packages/unittest/test/completion_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/unittest/test/breath_test.dart
diff --git a/packages/unittest/test/breath_test.dart b/packages/unittest/test/breath_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..244d2d2cf90ab3a9aa24ffc5ea1050a064b265dc
--- /dev/null
+++ b/packages/unittest/test/breath_test.dart
@@ -0,0 +1,51 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library unittest.breath_test;
+
+import 'dart:async';
+
+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;
+
+ test('initial', () {
+ Timer.run(() {
+ sentinel = 1;
+ });
+ });
+
+ test('starve', () {
+ // 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.inMilliseconds <= BREATH_INTERVAL) {
+ expect(sentinel, 0);
+ }
+
+ // 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.inMilliseconds < BREATH_INTERVAL);
+ });
+
+ test('breathed', () {
+ expect(sentinel, 1);
+ });
+ });
+}
« no previous file with comments | « packages/unittest/test/async_setup_teardown_test.dart ('k') | packages/unittest/test/completion_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698