diff --git a/test/dotnet-watch.FunctionalTests/FileWatcherTests.cs b/test/dotnet-watch.FunctionalTests/FileWatcherTests.cs index 9f1cc132bc..60fd501ca8 100644 --- a/test/dotnet-watch.FunctionalTests/FileWatcherTests.cs +++ b/test/dotnet-watch.FunctionalTests/FileWatcherTests.cs @@ -8,12 +8,19 @@ using System.Linq; using System.Threading; using Microsoft.DotNet.Watcher.Internal; using Xunit; +using Xunit.Abstractions; namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests { public class FileWatcherTests { + public FileWatcherTests(ITestOutputHelper output) + { + _output = output; + } + private const int DefaultTimeout = 10 * 1000; // 10 sec + private readonly ITestOutputHelper _output; [Theory] [InlineData(true)] @@ -277,16 +284,24 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests [InlineData(false)] public void MultipleTriggers(bool usePolling) { + var filesChanged = new HashSet(); + + void Clear() + { + _output.WriteLine("Clear files changed list"); + filesChanged.Clear(); + } + UsingTempDirectory(dir => { using (var changedEv = new AutoResetEvent(false)) using (var watcher = FileWatcherFactory.CreateWatcher(dir, usePolling)) { - var filesChanged = new HashSet(); EventHandler handler = null; handler = (_, f) => { + _output.WriteLine("File changed: " + f); filesChanged.Add(f); try { @@ -318,7 +333,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests Assert.True(changedEv.WaitOne(DefaultTimeout)); var fileChanged = Assert.Single(filesChanged); Assert.Equal(testFileFullPath, fileChanged); - filesChanged.Clear(); + Clear(); changedEv.Reset(); // On Unix the file write time is in 1s increments; @@ -331,7 +346,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests Assert.True(changedEv.WaitOne(DefaultTimeout)); fileChanged = Assert.Single(filesChanged); Assert.Equal(testFileFullPath, fileChanged); - filesChanged.Clear(); + Clear(); changedEv.Reset(); // On Unix the file write time is in 1s increments; @@ -342,8 +357,9 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests testFileFullPath = Path.Combine(dir, "foo3"); File.WriteAllText(testFileFullPath, string.Empty); Assert.True(changedEv.WaitOne(DefaultTimeout)); - Assert.Equal(testFileFullPath, filesChanged.Single()); - filesChanged.Clear(); + fileChanged = Assert.Single(filesChanged); + Assert.Equal(testFileFullPath, fileChanged); + Clear(); changedEv.Reset(); // On Unix the file write time is in 1s increments; diff --git a/test/dotnet-watch.FunctionalTests/NoDepsAppTests.cs b/test/dotnet-watch.FunctionalTests/NoDepsAppTests.cs index ea9ffbec03..8ac2f694e7 100644 --- a/test/dotnet-watch.FunctionalTests/NoDepsAppTests.cs +++ b/test/dotnet-watch.FunctionalTests/NoDepsAppTests.cs @@ -1,11 +1,10 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; -using Microsoft.AspNetCore.Testing; using Xunit; using Xunit.Abstractions; @@ -47,6 +46,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests await _app.StartWatcherAsync(); var pid = await _app.GetProcessId(); await _app.HasExited(); // process should exit after run + await _app.IsWaitingForFileChange(); var fileToChange = Path.Combine(_app.SourceDirectory, "Program.cs"); var programCs = File.ReadAllText(fileToChange); diff --git a/test/dotnet-watch.FunctionalTests/Scenario/WatchableApp.cs b/test/dotnet-watch.FunctionalTests/Scenario/WatchableApp.cs index 16bfbacc8d..56702afac2 100644 --- a/test/dotnet-watch.FunctionalTests/Scenario/WatchableApp.cs +++ b/test/dotnet-watch.FunctionalTests/Scenario/WatchableApp.cs @@ -19,6 +19,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests private const string StartedMessage = "Started"; private const string ExitingMessage = "Exiting"; private const string WatchExitedMessage = "watch : Exited"; + private const string WaitingForFileChangeMessage = "watch : Waiting for a file to change"; private readonly ITestOutputHelper _logger; private string _appName; @@ -49,6 +50,11 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests await Process.GetOutputLineAsync(WatchExitedMessage, DefaultMessageTimeOut); } + public async Task IsWaitingForFileChange() + { + await Process.GetOutputLineStartsWithAsync(WaitingForFileChangeMessage, DefaultMessageTimeOut); + } + public bool UsePollingWatcher { get; set; } public async Task GetProcessId()