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

Unified Diff: test/file_watcher/shared.dart

Issue 1228703007: Fix a race condition in file watcher. (Closed) Base URL: git@github.com:dart-lang/watcher@master
Patch Set: Created 5 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
« lib/src/file_watcher/polling.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/file_watcher/shared.dart
diff --git a/test/file_watcher/shared.dart b/test/file_watcher/shared.dart
index 2931d80228ac6a3803a737e4791da2c1a94ef048..9a4965cccccc8a39621b00f6e2b70ce9b7344ebf 100644
--- a/test/file_watcher/shared.dart
+++ b/test/file_watcher/shared.dart
@@ -2,6 +2,8 @@
// 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';
@@ -55,4 +57,19 @@ void sharedTests() {
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();
+ });
+ });
}
« lib/src/file_watcher/polling.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698