Repository navigation
Make test file watchers more resilient - #131304
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Pull request overview
Improves resiliency of Microsoft.Extensions.Configuration functional tests that validate reload-on-change behavior, aiming to reduce flakiness in file watcher–driven tests (notably on Linux/containerized/stress environments).
Changes:
- Replace one-shot file writes +
WaitForChangepolling with a newWaitForReloadhelper that re-applies file writes on each retry until the expected reload is observed. - Update the relative-path change-token test to use a
TaskCompletionSourcesignal and dispose theChangeToken.OnChangesubscription. - Re-enable several previously
[ActiveIssue]-skipped reload tests by making their wait logic more tolerant of missed/delayed notifications.
|
I'm not convinced writing to the file repeatedly is necessary here. Other notes:
|
|
Tagging subscribers to this area: @dotnet/area-extensions-filesystem |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:544
- The skip message references
System.IO.FileSystem.Watcher, but the API name isSystem.IO.FileSystemWatcher(no dot). This message is user-visible in test output; please fix the typo for clarity.
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS, "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS")]
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:915
- The skip message references
System.IO.FileSystem.Watcher, but the API name isSystem.IO.FileSystemWatcher(no dot). This message is user-visible in test output; please fix the typo for clarity.
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS, "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS")]
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:513
- The skip message references
System.IO.FileSystem.Watcher, but the API name isSystem.IO.FileSystemWatcher(no dot). This message is user-visible in test output; please fix the typo for clarity.
This issue also appears in the following locations of the same file:
- line 544
- line 915
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS, "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS")]
Resolves the conflict in ConfigurationTests.cs caused by dotnet#126093, which added six OnLoadException tests immediately after ReloadOnChangeWorksAfterError and removed OnLoadErrorCanIgnoreErrors. Both sides kept: - upstream's six new tests, with their [ActiveIssue]/[PlatformSpecific] attributes untouched; - this branch's [SkipOnPlatform] guard on TouchingFileWillReload, replacing the [ActiveIssue] quarantine it carried on main. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 21a523e1-0a42-4c98-b0a0-9850b1c3c03b
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:737
- The skip reason mentions a non-existent type name (
System.IO.FileSystem.Watcher). The .NET type isSystem.IO.FileSystemWatcher, so the message is misleading.
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS, "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS")]
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:1108
- The skip reason mentions a non-existent type name (
System.IO.FileSystem.Watcher). The .NET type isSystem.IO.FileSystemWatcher, so the message is misleading.
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS, "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS")]
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:490
- The skip reason mentions a non-existent type name (
System.IO.FileSystem.Watcher). The .NET type isSystem.IO.FileSystemWatcher, so the message is misleading.
This issue also appears in the following locations of the same file:
- line 737
- line 1108
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.tvOS, "System.IO.FileSystem.Watcher is not supported on Browser/iOS/tvOS")]
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:1278
- The cleanup
catch { }aroundFile.Deleteswallows all exceptions, which can hide unexpected problems (e.g., invalid paths). It’s safer to only swallow the common cleanup failures and let other exceptions surface.
try
{
File.Delete(watchedFilePath);
}
catch
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:1152
- The cleanup
catch { }aroundDirectory.Deleteswallows all exceptions (including unexpected ones likeArgumentException). In tests it's reasonable to ignore expected cleanup failures, but it should be limited to the known I/O-related exceptions to avoid masking real bugs (e.g., an invalid path being produced).
This issue also appears on line 1274 of the same file.
try
{
Directory.Delete(userSecretsFolder, true);
}
catch
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (3)
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:1265
- After renaming the max-wait field for consistency, update this call site to use the new name.
await Task.WhenAny(reloadedSignal.Task, Task.Delay(s_maxWaitForReload));
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:25
s_maxWaitForReloadintroduces ans_-prefixed static field in a file that otherwise uses_-prefixed private fields (including other static readonly fields). This makes the naming inconsistent within the same test class.
This issue also appears on line 1265 of the same file.
private static readonly TimeSpan s_maxWaitForReload = TimeSpan.FromSeconds(30);
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:1135
- This failure message mentions "create-delete-create", but this test is validating reload after updating the user secrets file. Updating the message will make failures more actionable.
await WaitForChange(
() => config["UserSecretKey1"] == "UserSecretValue2",
"Reload failed after create-delete-create.");
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/libraries/Microsoft.Extensions.Configuration/tests/FunctionalTests/ConfigurationTests.cs:1144
- In TouchingFileWillReloadForUserSecrets, disposing the IConfigurationRoot stops the ChangeToken registrations, but it doesn’t dispose the PhysicalFileProvider instance created by AddUserSecrets (the FileConfigurationProvider intentionally does not dispose Source.FileProvider). That can leave file watchers alive and make Directory.Delete(userSecretsFolder, ...) fail (currently swallowed), leaking secrets folders over time.
Consider grabbing the provider’s Source.FileProvider before disposing the config and dispose it explicitly.
// Stop watching before removing the folder the watcher is pointed at.
(config as IDisposable)?.Dispose();
Fixes #126726