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

Unified Diff: packages/watcher/test/file_watcher/shared.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
Index: packages/watcher/test/file_watcher/shared.dart
diff --git a/packages/watcher/test/file_watcher/shared.dart b/packages/watcher/test/file_watcher/shared.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9a4965cccccc8a39621b00f6e2b70ce9b7344ebf
--- /dev/null
+++ b/packages/watcher/test/file_watcher/shared.dart
@@ -0,0 +1,75 @@
+// Copyright (c) 2015, 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 'package:scheduled_test/scheduled_test.dart';
+import 'package:watcher/src/utils.dart';
+
+import '../utils.dart';
+
+void sharedTests() {
+ test("doesn't notify if the file isn't modified", () {
+ startWatcher(path: "file.txt");
+ // Give the watcher time to fire events if it's going to.
+ schedule(() => pumpEventQueue());
+ deleteFile("file.txt");
+ expectRemoveEvent("file.txt");
+ });
+
+ test("notifies when a file is modified", () {
+ startWatcher(path: "file.txt");
+ writeFile("file.txt", contents: "modified");
+ expectModifyEvent("file.txt");
+ });
+
+ test("notifies when a file is removed", () {
+ startWatcher(path: "file.txt");
+ deleteFile("file.txt");
+ expectRemoveEvent("file.txt");
+ });
+
+ test("notifies when a file is modified multiple times", () {
+ startWatcher(path: "file.txt");
+ writeFile("file.txt", contents: "modified");
+ expectModifyEvent("file.txt");
+ writeFile("file.txt", contents: "modified again");
+ expectModifyEvent("file.txt");
+ });
+
+ test("notifies even if the file contents are unchanged", () {
+ startWatcher(path: "file.txt");
+ writeFile("file.txt");
+ expectModifyEvent("file.txt");
+ });
+
+ test("emits a remove event when the watched file is moved away", () {
+ startWatcher(path: "file.txt");
+ renameFile("file.txt", "new.txt");
+ expectRemoveEvent("file.txt");
+ });
+
+ test("emits a modify event when another file is moved on top of the watched "
+ "file", () {
+ writeFile("old.txt");
+ startWatcher(path: "file.txt");
+ renameFile("old.txt", "file.txt");
+ expectModifyEvent("file.txt");
+ });
+
+ // Regression test for a race condition.
+ test("closes the watcher immediately after deleting the file", () {
+ writeFile("old.txt");
+ var watcher = createWatcher(path: "file.txt", waitForReady: false);
+ var sub = schedule(() => watcher.events.listen(null));
+
+ deleteFile("file.txt");
+ schedule(() async {
+ // Reproducing the race condition will always be flaky, but this sleep
+ // helped it reproduce more consistently on my machine.
+ await new Future.delayed(new Duration(milliseconds: 10));
+ (await sub).cancel();
+ });
+ });
+}
« no previous file with comments | « packages/watcher/test/file_watcher/polling_test.dart ('k') | packages/watcher/test/no_subscription/linux_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698