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

Unified Diff: pkg/watcher/test/no_subscription_test.dart

Issue 18877005: Split up tests and add some heartbeats to try to make them not timeout. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix cut/paste error. 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
Index: pkg/watcher/test/no_subscription_test.dart
diff --git a/pkg/watcher/test/no_subscription_test.dart b/pkg/watcher/test/no_subscription_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e9cb4e363734bd0709928d07d9b044b01f28a8ca
--- /dev/null
+++ b/pkg/watcher/test/no_subscription_test.dart
@@ -0,0 +1,73 @@
+// 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.
+
+import 'dart:async';
+import 'dart:io';
+
+import 'package:scheduled_test/scheduled_test.dart';
+import 'package:watcher/watcher.dart';
+
+import 'utils.dart';
+
+main() {
+ initConfig();
+
+ setUp(createSandbox);
+
+ test('does not notify for changes when there were no subscribers', () {
+ // Note that this test doesn't rely as heavily on the test functions in
+ // utils.dart because it needs to be very explicit about when the event
+ // stream is and is not subscribed.
+ var watcher = createWatcher();
+
+ // Subscribe to the events.
+ var completer = new Completer();
+ var subscription = watcher.events.listen((event) {
+ expect(event.type, equals(ChangeType.ADD));
+ expect(event.path, endsWith("file.txt"));
+ completer.complete();
+ });
+
+ writeFile("file.txt");
+
+ // Then wait until we get an event for it.
+ schedule(() => completer.future);
+
+ // Unsubscribe.
+ schedule(() {
+ subscription.cancel();
+ });
+
+ // Now write a file while we aren't listening.
+ writeFile("unwatched.txt");
+
+ // Then start listening again.
+ schedule(() {
+ completer = new Completer();
+ subscription = watcher.events.listen((event) {
+ // We should get an event for the third file, not the one added while
+ // we weren't subscribed.
+ expect(event.type, equals(ChangeType.ADD));
+ expect(event.path, endsWith("added.txt"));
+ completer.complete();
+ });
+ });
+
+ // The watcher will have been cancelled and then resumed in the middle of
+ // its pause between polling loops. That means the second scan to skip
+ // what changed while we were unsubscribed won't happen until after that
+ // delay is done. Wait long enough for that to happen.
+ schedule(() => new Future.delayed(new Duration(seconds: 1)));
+
+ // And add a third file.
+ writeFile("added.txt");
+
+ // Wait until we get an event for the third file.
+ schedule(() => completer.future);
+
+ schedule(() {
+ subscription.cancel();
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698