From 1830f4f0ddc4aa3234e0dd7b08b31ab984e2b714 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Fri, 1 Mar 2019 15:03:21 -0800 Subject: [PATCH] Avoid race in FileWatcher test Internal/1710 (#8095) --- src/Tools/Tools.sln | 31 +++++++++++++++++++ .../dotnet-watch/test/FileWatcherTests.cs | 13 ++++---- 2 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 src/Tools/Tools.sln diff --git a/src/Tools/Tools.sln b/src/Tools/Tools.sln new file mode 100644 index 0000000000..a2e2452067 --- /dev/null +++ b/src/Tools/Tools.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.0.0 +MinimumVisualStudioVersion = 16.0.0.0 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-watch", "dotnet-watch\src\dotnet-watch.csproj", "{E16F10C8-5FC3-420B-AB33-D6E5CBE89B75}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-watch.Tests", "dotnet-watch\test\dotnet-watch.Tests.csproj", "{63F7E822-D1E2-4C41-8ABF-60B9E3A9C54C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E16F10C8-5FC3-420B-AB33-D6E5CBE89B75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E16F10C8-5FC3-420B-AB33-D6E5CBE89B75}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E16F10C8-5FC3-420B-AB33-D6E5CBE89B75}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E16F10C8-5FC3-420B-AB33-D6E5CBE89B75}.Release|Any CPU.Build.0 = Release|Any CPU + {63F7E822-D1E2-4C41-8ABF-60B9E3A9C54C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63F7E822-D1E2-4C41-8ABF-60B9E3A9C54C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63F7E822-D1E2-4C41-8ABF-60B9E3A9C54C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63F7E822-D1E2-4C41-8ABF-60B9E3A9C54C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EC668D8E-97B9-4758-9E5C-2E5DD6B9137B} + EndGlobalSection +EndGlobal diff --git a/src/Tools/dotnet-watch/test/FileWatcherTests.cs b/src/Tools/dotnet-watch/test/FileWatcherTests.cs index 6b9e8c354d..c0ea5c0191 100644 --- a/src/Tools/dotnet-watch/test/FileWatcherTests.cs +++ b/src/Tools/dotnet-watch/test/FileWatcherTests.cs @@ -246,7 +246,13 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests File.WriteAllText(Path.Combine(dir, "foo2"), string.Empty); File.WriteAllText(Path.Combine(dir, "foo3"), string.Empty); File.WriteAllText(Path.Combine(dir, "foo4"), string.Empty); - File.WriteAllText(Path.Combine(dir, "foo4"), string.Empty); + + // On Unix the native file watcher may surface events from + // the recent past. Delay to avoid those. + // On Unix the file write time is in 1s increments; + // if we don't wait, there's a chance that the polling + // watcher will not detect the change + await Task.Delay(1250); var testFileFullPath = Path.Combine(dir, "foo3"); @@ -267,11 +273,6 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests watcher.OnFileChange += handler; watcher.EnableRaisingEvents = true; - // On Unix the file write time is in 1s increments; - // if we don't wait, there's a chance that the polling - // watcher will not detect the change - await Task.Delay(1000); - File.WriteAllText(testFileFullPath, string.Empty); await changedEv.Task.TimeoutAfter(DefaultTimeout);