From 8ab32c44f7d9bf30ed80295bc4579dd43bd31ae4 Mon Sep 17 00:00:00 2001 From: Victor Hurdugaci Date: Wed, 25 May 2016 11:48:20 -0700 Subject: [PATCH] Make RestartProcessThatTerminatesAfterFileChange more reliable --- .../NoDepsAppTests.cs | 6 ++++++ .../Waiters.cs | 10 ++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/NoDepsAppTests.cs b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/NoDepsAppTests.cs index 6a4fa1b542..1b7109828c 100644 --- a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/NoDepsAppTests.cs +++ b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/NoDepsAppTests.cs @@ -4,6 +4,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Threading; using Xunit; namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests @@ -79,6 +80,11 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests // Then wait for it to restart when we change a file using (var wait = new WaitForFileToChange(scenario.StartedFile)) { + // 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 + Thread.Sleep(1000); + var fileToChange = Path.Combine(scenario.TestAppFolder, "Program.cs"); var programCs = File.ReadAllText(fileToChange); File.WriteAllText(fileToChange, programCs); diff --git a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Waiters.cs b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Waiters.cs index 113d339769..de8c0f7f3f 100644 --- a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Waiters.cs +++ b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Waiters.cs @@ -44,6 +44,8 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests public static void WaitForProcessToStop(int processId, TimeSpan timeout, bool expectedToStop, string errorMessage) { + Console.WriteLine($"Waiting for process {processId} to stop..."); + Process process = null; try @@ -52,8 +54,11 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests } catch (Exception e) { - Console.WriteLine("Could not get process id:"); - Console.WriteLine(e); + // If we expect the process to stop, then it might have stopped already + if (!expectedToStop) + { + Console.WriteLine($"Could not find process {processId}: {e}"); + } } var watch = new Stopwatch(); @@ -62,6 +67,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests { if (process == null || process.HasExited) { + Console.WriteLine($"Process {processId} is no longer running"); break; } Thread.Sleep(500);