From 383ae438219bdacf79c1d5de0ddecbb2a192d42f Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:02:19 +0000 Subject: [PATCH 1/2] fix: Report the files of a watched directory that disappears during the periodic check The periodic check observed a directory's files and then asked whether the directory exists. A directory moved away between the two was found missing with its files present: its watch was dropped without a report, the later checks skip a directory without a watch, and the absence of the files went unreported until the directory came back. The check now observes the files again once it finds the directory missing. This made FileDataWatcherTest.DirectoryRemovedWithoutNotificationsIsReportedOnce flaky on a loaded Linux box: its 300 ms wait is six check intervals, so the move lands within milliseconds of a check. A test seam for the directory existence question moves the directory away just before or just after the check asks, which reproduces the lost report deterministically. --- .../Internal/FileLoading/FileDataWatcher.cs | 26 ++++++++++-- .../FileLoading/FileDataWatcherTest.cs | 40 +++++++++++++++++++ 2 files changed, 62 insertions(+), 4 deletions(-) diff --git a/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs b/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs index 74e7dded9..b3ef05139 100644 --- a/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs +++ b/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs @@ -76,6 +76,7 @@ internal WatchedDirectory(string path) private readonly List _directories = new List(); private readonly Action _onChange; private readonly Logger _log; + private readonly Func _directoryExists; private readonly Timer _timer; private int _checking; private volatile bool _disposed; @@ -92,10 +93,19 @@ internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log) { } - internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log, TimeSpan checkInterval) + internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log, TimeSpan checkInterval) : + this(paths, onChange, log, checkInterval, Directory.Exists) + { + } + + // The directoryExists parameter tells whether a directory exists. A test supplies its own to + // change the file system at a chosen point of a check. + internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log, TimeSpan checkInterval, + Func directoryExists) { _onChange = onChange; _log = log ?? Logs.None.Logger(""); + _directoryExists = directoryExists; // The full path of each file is computed once. Notifications carry the entry name, which // is compared to the configured names of the directory. @@ -220,7 +230,7 @@ private FileSystemWatcher CreateWatcher(WatchedDirectory directory) // attempt. Repeats of an identical failure are demoted to debug level. private void LogSetupFailure(WatchedDirectory directory, Exception e) { - var key = Directory.Exists(directory.Path) ? e.Message : MissingDirectoryKey; + var key = _directoryExists(directory.Path) ? e.Message : MissingDirectoryKey; if (key == directory.LastFailureKey) { _log.Debug("Unable to watch directory {0}: {1}", directory.Path, LogValues.ExceptionSummary(e)); @@ -294,7 +304,7 @@ private void OnWatcherError(WatchedDirectory directory, FileSystemWatcher watche return; } directory.Watcher = null; - if (Directory.Exists(directory.Path)) + if (_directoryExists(directory.Path)) { LogHelpers.LogException(_log, "Error from file system watcher for directory " + directory.Path, error); } @@ -371,13 +381,21 @@ private void OnCheck(object state) var notified = directory.NotifiedSinceCheck; directory.NotifiedSinceCheck = false; var current = FileState.ObserveAll(directory.Files); + var directoryExists = _directoryExists(directory.Path); + if (!directoryExists) + { + // The directory can have gone after its files were observed. They are + // observed again, or a dropped watch would leave their absence + // unreported until the directory came back. + current = FileState.ObserveAll(directory.Files); + } var stateChanged = FileState.AnyChanged(directory.LastStates, current); if (stateChanged) { directory.LastStates = current; changed = true; } - if (!Directory.Exists(directory.Path)) + if (!directoryExists) { toDispose.Add(directory.Watcher); directory.Watcher = null; diff --git a/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs b/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs index 0090b701e..3839ed1f2 100644 --- a/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs +++ b/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs @@ -252,6 +252,46 @@ public void DirectoryRemovedWithoutNotificationsIsReportedOnce() RequireNoChange(); } + [Theory] + [InlineData(true)] + [InlineData(false)] + public void DirectoryRemovedDuringACheckIsReportedOnce(bool beforeTheAnswer) + { + var directory = _dir.PathOf("removed"); + Directory.CreateDirectory(directory); + var path = Path.Combine(directory, "data.json"); + File.WriteAllText(path, "one"); + + // Once armed, the next question whether the directory exists moves the directory away, + // just before or just after it is answered. The move lands inside a check, and the + // platform reports nothing for it. + var armed = 0; + Func directoryExists = candidate => + { + var fire = Interlocked.Exchange(ref armed, 0) == 1; + if (fire && beforeTheAnswer) + { + Directory.Move(directory, _dir.PathOf("removed-elsewhere")); + } + var exists = Directory.Exists(candidate); + if (fire && !beforeTheAnswer) + { + Directory.Move(directory, _dir.PathOf("removed-elsewhere")); + } + return exists; + }; + _watcher = new FileDataWatcher(new[] { path }, () => _changes.Add(true), TestLogger, CheckInterval, + directoryExists); + DiscardStaleNotifications(); + Interlocked.Exchange(ref armed, 1); + + // Either way, the absence of the file is a change, the watch is dropped as that of a + // missing directory, and nothing more is reported while the directory stays missing. + RequireChange(); + RequireLogMessage(Logging.LogLevel.Warn, "no longer exists"); + RequireNoChange(); + } + [Fact] public void DirectoryReplacedBetweenChecksIsWatchedAgain() { From 2fc770d9972e99b974d936507e45a22d44f2f927 Mon Sep 17 00:00:00 2001 From: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:38:19 +0000 Subject: [PATCH 2/2] fix: Check the files of directories that have no watch A directory whose watch was dropped was skipped by the periodic check until its watch was set up again. When the directory went away with its files after the drop, for example after a watch error or a change without a notification, the setup failed with an error log and the absence of the files went unreported until the directory came back. A directory that could never be watched, for example at the inotify limit, never had its files checked. The check now compares the files of every directory against a baseline taken at startup, watched or not. A directory that was watched and is missing when its watch is set up again is logged as a missing directory rather than as a setup failure. A check, or a watch error, now runs the callback once even when it both finds a change and sets up a watch. The watcher takes the function that creates a watch as a test seam, which lets the tests raise a watch error, provide a watch that delivers nothing, and fail every setup. --- .../Internal/FileLoading/FileDataWatcher.cs | 171 ++++++++++-------- .../FileLoading/FileDataWatcherTest.cs | 145 ++++++++++++++- 2 files changed, 235 insertions(+), 81 deletions(-) diff --git a/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs b/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs index b3ef05139..804c29c98 100644 --- a/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs +++ b/pkgs/sdk/server/src/Internal/FileLoading/FileDataWatcher.cs @@ -30,13 +30,17 @@ namespace LaunchDarkly.Sdk.Server.Internal.FileLoading /// other directories are watched. A watch on a directory that is deleted delivers nothing more. /// Some platforms report the deletion as an error of the watch, and others report neither the /// deletion nor a new directory of the same name. So once a second the watcher checks that each - /// directory exists and that the state of each configured file matches its last notification. - /// A directory that no longer exists, whether the platform reported it or the check found it, - /// has its watch dropped and set up again once it exists. A file whose state changed without a - /// notification is reported, and its directory's watch is set up again because it can be dead, - /// unless the watch delivered a notification since the previous check: a watch that delivers - /// is alive, and the notification for the change can still be on its way. When a watch is set - /// up after a failure, the callback runs once so that changes made in the meantime are picked up. + /// watched directory exists, and that the state of each configured file matches its last + /// observation, whether its directory is watched or not. A directory that no longer exists, + /// whether the platform reported it or the check found it, has its watch dropped and set up + /// again once it exists. A file whose state changed without a notification is reported, and its + /// directory's watch is set up again because it can be dead, unless the watch delivered a + /// notification since the previous check: a watch that delivers is alive, and the notification + /// for the change can still be on its way. Because the files of a directory without a watch are + /// checked too, a change is reported while a directory cannot be watched or is missing, + /// including the disappearance of a directory together with its files. When a watch is set up + /// after a failure, the callback runs so that changes made in the meantime are picked up, and a + /// check runs it at most once. /// /// internal sealed class FileDataWatcher : IDisposable @@ -59,6 +63,8 @@ private sealed class WatchedDirectory internal readonly HashSet Names = new HashSet(StringComparer.Ordinal); // Null while the directory is not watched. internal FileSystemWatcher Watcher; + // True once a watch on the directory has been set up. + internal bool WasWatched; // The last observed state of each file, in the order of Files. internal FileState[] LastStates; // The key of the last reported setup failure, or null after a successful setup. @@ -77,6 +83,7 @@ internal WatchedDirectory(string path) private readonly Action _onChange; private readonly Logger _log; private readonly Func _directoryExists; + private readonly Func _newWatcher; private readonly Timer _timer; private int _checking; private volatile bool _disposed; @@ -93,19 +100,18 @@ internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log) { } - internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log, TimeSpan checkInterval) : - this(paths, onChange, log, checkInterval, Directory.Exists) - { - } - - // The directoryExists parameter tells whether a directory exists. A test supplies its own to - // change the file system at a chosen point of a check. + // A test can supply the two functions through which the watcher reaches the file system, to + // change the file system at a chosen point or to control the watches. directoryExists tells + // whether a directory exists; the periodic check, LogSetupFailure and OnWatcherError ask it. + // newWatcher creates the watch on a directory, and throws if the directory cannot be watched. + // Null selects the file system's own. internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log, TimeSpan checkInterval, - Func directoryExists) + Func directoryExists = null, Func newWatcher = null) { _onChange = onChange; _log = log ?? Logs.None.Logger(""); - _directoryExists = directoryExists; + _directoryExists = directoryExists ?? Directory.Exists; + _newWatcher = newWatcher ?? (path => new FileSystemWatcher(path)); // The full path of each file is computed once. Notifications carry the entry name, which // is compared to the configured names of the directory. @@ -122,8 +128,15 @@ internal FileDataWatcher(IEnumerable paths, Action onChange, Logger log, directory.Files.Add(fullPath); directory.Names.Add(Path.GetFileName(fullPath)); } + // The baseline that the periodic check compares the files of a directory to until its + // watch is set up, if it cannot be watched now. + foreach (var directory in _directories) + { + directory.LastStates = FileState.ObserveAll(directory.Files); + } - SetUpWatches(isRetry: false); + // The files have just been observed, so the first setup has no changes to report. + SetUpWatches(); _timer = new Timer(OnCheck, null, checkInterval, checkInterval); } @@ -143,16 +156,17 @@ public void Dispose() } // Sets up the watch on each directory that has none. A directory that cannot be watched is - // attempted again at the next check. When a setup after a failure succeeds, the callback - // runs once, because the files can have changed while the directory was not watched. - private void SetUpWatches(bool isRetry) + // attempted again at the next check. Returns true if a watch was set up. After a failure the + // caller then runs the callback, because the files can have changed while the directory was + // not watched. + private bool SetUpWatches() { - var signal = false; + var setUp = false; lock (_lock) { if (_disposed) { - return; + return false; } foreach (var directory in _directories) { @@ -173,49 +187,42 @@ private void SetUpWatches(bool isRetry) { // Dispose ran while this watch was being created and found none to drop. Interlocked.Exchange(ref directory.Watcher, null)?.Dispose(); - return; + return false; } if (directory.LastFailureKey != null) { _log.Info("Now watching directory {0}", directory.Path); directory.LastFailureKey = null; } + directory.WasWatched = true; // The states are the baseline that a later notification for another entry is // compared to. directory.LastStates = FileState.ObserveAll(directory.Files); - if (isRetry) - { - signal = true; - } + setUp = true; } } - if (signal) - { - _onChange(); - } + return setUp; } private FileSystemWatcher CreateWatcher(WatchedDirectory directory) { - var watcher = new FileSystemWatcher(directory.Path) - { - NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.FileName | - NotifyFilters.CreationTime, - IncludeSubdirectories = false - }; - // The handlers carry the watcher they were attached to, so a notification from a watcher - // that has been dropped is ignored. - watcher.Changed += (sender, args) => OnFileEvent(directory, watcher, args.Name); - watcher.Created += (sender, args) => OnFileEvent(directory, watcher, args.Name); - watcher.Deleted += (sender, args) => OnFileEvent(directory, watcher, args.Name); - watcher.Renamed += (sender, args) => - { - OnFileEvent(directory, watcher, args.OldName); - OnFileEvent(directory, watcher, args.Name); - }; - watcher.Error += (sender, args) => OnWatcherError(directory, watcher, args.GetException()); + var watcher = _newWatcher(directory.Path); try { + watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size | NotifyFilters.FileName | + NotifyFilters.CreationTime; + watcher.IncludeSubdirectories = false; + // The handlers carry the watcher they were attached to, so a notification from a + // watcher that has been dropped is ignored. + watcher.Changed += (sender, args) => OnFileEvent(directory, watcher, args.Name); + watcher.Created += (sender, args) => OnFileEvent(directory, watcher, args.Name); + watcher.Deleted += (sender, args) => OnFileEvent(directory, watcher, args.Name); + watcher.Renamed += (sender, args) => + { + OnFileEvent(directory, watcher, args.OldName); + OnFileEvent(directory, watcher, args.Name); + }; + watcher.Error += (sender, args) => OnWatcherError(directory, watcher, args.GetException()); watcher.EnableRaisingEvents = true; } catch (Exception) @@ -227,15 +234,23 @@ private FileSystemWatcher CreateWatcher(WatchedDirectory directory) } // Called inside the lock. A persistent failure would repeat the same log entry on every - // attempt. Repeats of an identical failure are demoted to debug level. + // attempt. Repeats of an identical failure are demoted to debug level. A directory that was + // watched and is missing now went away after its watch was dropped for another reason, such + // as an error of the watch, and is logged as a missing directory. private void LogSetupFailure(WatchedDirectory directory, Exception e) { - var key = _directoryExists(directory.Path) ? e.Message : MissingDirectoryKey; + var missing = !_directoryExists(directory.Path); + var key = missing ? MissingDirectoryKey : e.Message; if (key == directory.LastFailureKey) { _log.Debug("Unable to watch directory {0}: {1}", directory.Path, LogValues.ExceptionSummary(e)); return; } + if (missing && directory.WasWatched) + { + NoteMissingDirectory(directory); + return; + } directory.LastFailureKey = key; LogHelpers.LogException(_log, "Unable to watch directory " + directory.Path + "; will retry", e); } @@ -321,11 +336,11 @@ private void OnWatcherError(WatchedDirectory directory, FileSystemWatcher watche } } watcher.Dispose(); - if (changed) + var setUp = SetUpWatches(); + if (changed || setUp) { _onChange(); } - SetUpWatches(isRetry: true); } catch (Exception e) { @@ -333,24 +348,27 @@ private void OnWatcherError(WatchedDirectory directory, FileSystemWatcher watche } } - // Called inside the lock for a directory whose watch was dropped because the directory no - // longer exists. The setup failures that follow until it exists again repeat this cause, - // and are logged at debug level only. + // Called inside the lock for a directory that was watched and no longer exists. The setup + // failures that follow until it exists again repeat this cause, and are logged at debug + // level only. private void NoteMissingDirectory(WatchedDirectory directory) { _log.Warn("Directory {0} no longer exists; its watch is set up again when it appears", directory.Path); directory.LastFailureKey = MissingDirectoryKey; } - // The periodic check. A configured file whose state differs from its last notification - // changed without one, and the change is reported. A directory that no longer exists has - // its watch dropped; its files are absent now, which is such a change when their deletion - // produced no notification. Otherwise the watch of a directory with a changed file is set up - // again, because a watch that reports nothing for a changed file can be dead, for example - // when the directory was replaced by a new one of the same name. A watch that delivered a - // notification since the previous check is alive, and the notification for this change can - // still be on its way, so that watch is kept. Finally, every directory without a watch gets - // one set up. + // The periodic check. A configured file whose state differs from its last observation + // changed without a notification, and the change is reported. This includes the files of a + // directory without a watch, which nothing else observes: a directory that cannot be + // watched, or one that went away, with its files, after its watch was dropped. A watched + // directory that no longer exists has its watch dropped; its files are absent now, which is + // such a change when their deletion produced no notification. Otherwise the watch of a + // directory with a changed file is set up again, because a watch that reports nothing for a + // changed file can be dead, for example when the directory was replaced by a new one of the + // same name. A watch that delivered a notification since the previous check is alive, and + // the notification for this change can still be on its way, so that watch is kept. Finally, + // every directory without a watch gets one set up, and the callback runs once if anything + // changed or a watch was set up. private void OnCheck(object state) { if (_disposed) @@ -374,28 +392,23 @@ private void OnCheck(object state) } foreach (var directory in _directories) { - if (directory.Watcher == null) - { - continue; - } var notified = directory.NotifiedSinceCheck; directory.NotifiedSinceCheck = false; var current = FileState.ObserveAll(directory.Files); - var directoryExists = _directoryExists(directory.Path); - if (!directoryExists) - { - // The directory can have gone after its files were observed. They are - // observed again, or a dropped watch would leave their absence - // unreported until the directory came back. - current = FileState.ObserveAll(directory.Files); - } var stateChanged = FileState.AnyChanged(directory.LastStates, current); if (stateChanged) { directory.LastStates = current; changed = true; } - if (!directoryExists) + if (directory.Watcher == null) + { + continue; + } + // A directory that goes away after its files were observed is found + // missing with its files present. Its watch is dropped, and the next check + // finds the files absent. + if (!_directoryExists(directory.Path)) { toDispose.Add(directory.Watcher); directory.Watcher = null; @@ -413,11 +426,11 @@ private void OnCheck(object state) { dropped.Dispose(); } - if (changed) + var setUp = SetUpWatches(); + if (changed || setUp) { _onChange(); } - SetUpWatches(isRetry: true); } catch (Exception e) { diff --git a/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs b/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs index 3839ed1f2..0d7f705ad 100644 --- a/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs +++ b/pkgs/sdk/server/test/Internal/FileLoading/FileDataWatcherTest.cs @@ -32,6 +32,29 @@ private FileDataWatcher StartWatcher(params string[] paths) return _watcher; } + // Starts a watcher that reaches the file system through the given functions. + private void StartControlledWatcher(string path, Func directoryExists = null, + Func newWatcher = null) + { + _watcher = new FileDataWatcher(new[] { path }, () => _changes.Add(true), TestLogger, CheckInterval, + directoryExists, newWatcher); + } + + // A watch whose errors a test raises. + private sealed class ErrorRaisingWatcher : FileSystemWatcher + { + internal ErrorRaisingWatcher(string path) : base(path) { } + + internal void RaiseError(Exception e) => OnError(new ErrorEventArgs(e)); + } + + // Changes the modification time of the file in one step. + private static void TouchFile(string path) => + File.SetLastWriteTimeUtc(path, File.GetLastWriteTimeUtc(path).AddMinutes(-5)); + + private void RequireNoSetupFailureLogged() => + AssertLogMessageRegex(false, Logging.LogLevel.Error, "Unable to watch directory"); + private void RequireChange() => Assert.True(_changes.TryTake(out _, TestTimeout), "expected a change notification"); @@ -280,8 +303,7 @@ public void DirectoryRemovedDuringACheckIsReportedOnce(bool beforeTheAnswer) } return exists; }; - _watcher = new FileDataWatcher(new[] { path }, () => _changes.Add(true), TestLogger, CheckInterval, - directoryExists); + StartControlledWatcher(path, directoryExists: directoryExists); DiscardStaleNotifications(); Interlocked.Exchange(ref armed, 1); @@ -290,6 +312,125 @@ public void DirectoryRemovedDuringACheckIsReportedOnce(bool beforeTheAnswer) RequireChange(); RequireLogMessage(Logging.LogLevel.Warn, "no longer exists"); RequireNoChange(); + RequireNoSetupFailureLogged(); + + // The directory comes back with the file in it, which is a change. + Directory.Move(_dir.PathOf("removed-elsewhere"), directory); + RequireChange(); + } + + [Fact] + public void DirectoryMovedAfterAWatchErrorIsReportedOnce() + { + var directory = _dir.PathOf("removed"); + Directory.CreateDirectory(directory); + var path = Path.Combine(directory, "data.json"); + File.WriteAllText(path, "one"); + + // The first watch is one whose errors the test raises. The setup after the error moves + // the directory away before the watch is created, so that setup fails. + ErrorRaisingWatcher first = null; + var setups = 0; + StartControlledWatcher(path, newWatcher: candidate => + { + var setup = Interlocked.Increment(ref setups); + if (setup == 1) + { + return first = new ErrorRaisingWatcher(candidate); + } + if (setup == 2) + { + Directory.Move(directory, _dir.PathOf("removed-elsewhere")); + } + return new FileSystemWatcher(candidate); + }); + DiscardStaleNotifications(); + + first.RaiseError(new InternalBufferOverflowException()); + + // The absence of the file is a change, the directory is logged as missing, and nothing + // more is reported while it stays missing. + RequireChange(); + RequireLogMessage(Logging.LogLevel.Warn, "no longer exists"); + RequireNoChange(); + RequireNoSetupFailureLogged(); + } + + [Fact] + public void DirectoryMovedAfterAChangeWithoutANotificationIsReportedOnce() + { + var directory = _dir.PathOf("removed"); + Directory.CreateDirectory(directory); + var path = Path.Combine(directory, "data.json"); + File.WriteAllText(path, "one"); + var quiet = _dir.PathOf("quiet"); + Directory.CreateDirectory(quiet); + + // The first watch is on another directory, where nothing happens, so a change to the + // file comes with no notification. The setup after the check drops that watch moves the + // directory away before the watch is created, so that setup fails. + var setups = 0; + StartControlledWatcher(path, newWatcher: candidate => + { + var setup = Interlocked.Increment(ref setups); + if (setup == 1) + { + return new FileSystemWatcher(quiet); + } + if (setup == 2) + { + Directory.Move(directory, _dir.PathOf("removed-elsewhere")); + } + return new FileSystemWatcher(candidate); + }); + DiscardStaleNotifications(); + + // The change is reported, and then the absence of the file. The directory is logged as + // missing, and nothing more is reported while it stays missing. The change is one step, + // so that no check can find it half made. + TouchFile(path); + RequireChange(); + RequireChange(); + RequireLogMessage(Logging.LogLevel.Warn, "no longer exists"); + RequireNoChange(); + RequireNoSetupFailureLogged(); + } + + [Fact] + public void FilesInADirectoryThatCannotBeWatchedAreChecked() + { + var path = _dir.PathOf("data.json"); + File.WriteAllText(path, "one"); + + // Every setup fails, as it does when the platform's limit on watches has been reached. + StartControlledWatcher(path, newWatcher: candidate => + throw new IOException("The limit on the number of watches has been reached")); + AssertLogMessageRegex(true, Logging.LogLevel.Error, "Unable to watch directory"); + + TouchFile(path); + RequireChange(); + File.Delete(path); + RequireChange(); + } + + [Fact] + public void ChangeWithoutANotificationIsReportedOnce() + { + var path = _dir.PathOf("data.json"); + File.WriteAllText(path, "one"); + var quiet = _dir.PathOf("quiet"); + Directory.CreateDirectory(quiet); + + // Every watch is on another directory, where nothing happens, so a change to the file + // comes with no notification. The check that finds it drops the watch and sets up a new + // one, and the change is reported once. The change is one step, so that no check can + // find it half made. + StartControlledWatcher(path, newWatcher: candidate => new FileSystemWatcher(quiet)); + DiscardStaleNotifications(); + + TouchFile(path); + RequireChange(); + RequireNoChange(); } [Fact]