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

Side by Side 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 unified diff | Download patch
« lib/src/file_watcher/polling.dart ('K') | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async';
6
5 import 'package:scheduled_test/scheduled_test.dart'; 7 import 'package:scheduled_test/scheduled_test.dart';
6 import 'package:watcher/src/utils.dart'; 8 import 'package:watcher/src/utils.dart';
7 9
8 import '../utils.dart'; 10 import '../utils.dart';
9 11
10 void sharedTests() { 12 void sharedTests() {
11 test("doesn't notify if the file isn't modified", () { 13 test("doesn't notify if the file isn't modified", () {
12 startWatcher(path: "file.txt"); 14 startWatcher(path: "file.txt");
13 // Give the watcher time to fire events if it's going to. 15 // Give the watcher time to fire events if it's going to.
14 schedule(() => pumpEventQueue()); 16 schedule(() => pumpEventQueue());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 expectRemoveEvent("file.txt"); 50 expectRemoveEvent("file.txt");
49 }); 51 });
50 52
51 test("emits a modify event when another file is moved on top of the watched " 53 test("emits a modify event when another file is moved on top of the watched "
52 "file", () { 54 "file", () {
53 writeFile("old.txt"); 55 writeFile("old.txt");
54 startWatcher(path: "file.txt"); 56 startWatcher(path: "file.txt");
55 renameFile("old.txt", "file.txt"); 57 renameFile("old.txt", "file.txt");
56 expectModifyEvent("file.txt"); 58 expectModifyEvent("file.txt");
57 }); 59 });
60
61 // Regression test for a race condition.
62 test("closes the watcher immediately after deleting the file", () {
63 writeFile("old.txt");
64 var watcher = createWatcher(path: "file.txt", waitForReady: false);
65 var sub = schedule(() => watcher.events.listen(null));
66
67 deleteFile("file.txt");
68 schedule(() async {
69 // Reproducing the race condition will always be flaky, but this sleep
70 // helped it reproduce more consistently on my machine.
71 await new Future.delayed(new Duration(milliseconds: 10));
72 (await sub).cancel();
73 });
74 });
58 } 75 }
OLDNEW
« 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