Skip to content

Commit 93bc4e2

Browse files
svicktmds
authored andcommitted
Test that PhysicalFilesWatcher is triggered when the root directory is deleted
1 parent b854d9f commit 93bc4e2

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

src/libraries/Microsoft.Extensions.FileProviders.Physical/tests/PhysicalFilesWatcherTests.cs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -485,17 +485,23 @@ public async Task CreateFileChangeToken_RootDeletedAndRecreated_TokenFiresWhenFi
485485

486486
using var physicalFilesWatcher = CreateWatcher(rootPath, useActivePolling);
487487

488-
// On some platforms (e.g., Linux) the FSW does not fire OnError when the watched directory
489-
// is deleted (see https://github.com/dotnet/runtime/issues/126295), so we cannot wait
490-
// for the token to fire. Instead, wait briefly and then re-register after deleting the directory.
491-
physicalFilesWatcher.CreateFileChangeToken("file.txt");
488+
// When using a real FileSystemWatcher, deleting the watched directory fires OnError
489+
// which causes the token to fire. With polling there is no FSW, so we just wait briefly.
490+
IChangeToken initialToken = physicalFilesWatcher.CreateFileChangeToken("file.txt");
491+
492492
Directory.Delete(rootPath, recursive: true);
493-
await Task.Delay(WaitTimeForTokenToFire);
494493

495-
// Re-watch the same file — root is now missing, so this goes through PendingCreationWatcher where available
496-
IChangeToken token = physicalFilesWatcher.CreateFileChangeToken("file.txt");
494+
if (useActivePolling)
495+
{
496+
await Task.Delay(WaitTimeForTokenToFire);
497+
}
498+
else
499+
{
500+
await WhenChanged(initialToken);
501+
}
497502

498-
Task changed = WhenChanged(token);
503+
// Re-watch the same file — root is now missing, so this goes through PendingCreationWatcher where available
504+
Task changed = WhenChanged(physicalFilesWatcher.CreateFileChangeToken("file.txt"));
499505

500506
// Recreate the root — token must not fire yet
501507
Directory.CreateDirectory(rootPath);

0 commit comments

Comments
 (0)