Attempt to address flaky dotnet-watch tests
This commit is contained in:
parent
1b0ff08999
commit
3193f45bae
|
|
@ -8,12 +8,19 @@ using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Microsoft.DotNet.Watcher.Internal;
|
using Microsoft.DotNet.Watcher.Internal;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
{
|
{
|
||||||
public class FileWatcherTests
|
public class FileWatcherTests
|
||||||
{
|
{
|
||||||
|
public FileWatcherTests(ITestOutputHelper output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
private const int DefaultTimeout = 10 * 1000; // 10 sec
|
private const int DefaultTimeout = 10 * 1000; // 10 sec
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(true)]
|
[InlineData(true)]
|
||||||
|
|
@ -277,16 +284,24 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
[InlineData(false)]
|
[InlineData(false)]
|
||||||
public void MultipleTriggers(bool usePolling)
|
public void MultipleTriggers(bool usePolling)
|
||||||
{
|
{
|
||||||
|
var filesChanged = new HashSet<string>();
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
_output.WriteLine("Clear files changed list");
|
||||||
|
filesChanged.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
UsingTempDirectory(dir =>
|
UsingTempDirectory(dir =>
|
||||||
{
|
{
|
||||||
using (var changedEv = new AutoResetEvent(false))
|
using (var changedEv = new AutoResetEvent(false))
|
||||||
using (var watcher = FileWatcherFactory.CreateWatcher(dir, usePolling))
|
using (var watcher = FileWatcherFactory.CreateWatcher(dir, usePolling))
|
||||||
{
|
{
|
||||||
var filesChanged = new HashSet<string>();
|
|
||||||
|
|
||||||
EventHandler<string> handler = null;
|
EventHandler<string> handler = null;
|
||||||
handler = (_, f) =>
|
handler = (_, f) =>
|
||||||
{
|
{
|
||||||
|
_output.WriteLine("File changed: " + f);
|
||||||
filesChanged.Add(f);
|
filesChanged.Add(f);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -318,7 +333,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||||
var fileChanged = Assert.Single(filesChanged);
|
var fileChanged = Assert.Single(filesChanged);
|
||||||
Assert.Equal(testFileFullPath, fileChanged);
|
Assert.Equal(testFileFullPath, fileChanged);
|
||||||
filesChanged.Clear();
|
Clear();
|
||||||
changedEv.Reset();
|
changedEv.Reset();
|
||||||
|
|
||||||
// On Unix the file write time is in 1s increments;
|
// 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));
|
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||||
fileChanged = Assert.Single(filesChanged);
|
fileChanged = Assert.Single(filesChanged);
|
||||||
Assert.Equal(testFileFullPath, fileChanged);
|
Assert.Equal(testFileFullPath, fileChanged);
|
||||||
filesChanged.Clear();
|
Clear();
|
||||||
changedEv.Reset();
|
changedEv.Reset();
|
||||||
|
|
||||||
// On Unix the file write time is in 1s increments;
|
// 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");
|
testFileFullPath = Path.Combine(dir, "foo3");
|
||||||
File.WriteAllText(testFileFullPath, string.Empty);
|
File.WriteAllText(testFileFullPath, string.Empty);
|
||||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||||
Assert.Equal(testFileFullPath, filesChanged.Single());
|
fileChanged = Assert.Single(filesChanged);
|
||||||
filesChanged.Clear();
|
Assert.Equal(testFileFullPath, fileChanged);
|
||||||
|
Clear();
|
||||||
changedEv.Reset();
|
changedEv.Reset();
|
||||||
|
|
||||||
// On Unix the file write time is in 1s increments;
|
// On Unix the file write time is in 1s increments;
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Testing;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
|
@ -47,6 +46,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
await _app.StartWatcherAsync();
|
await _app.StartWatcherAsync();
|
||||||
var pid = await _app.GetProcessId();
|
var pid = await _app.GetProcessId();
|
||||||
await _app.HasExited(); // process should exit after run
|
await _app.HasExited(); // process should exit after run
|
||||||
|
await _app.IsWaitingForFileChange();
|
||||||
|
|
||||||
var fileToChange = Path.Combine(_app.SourceDirectory, "Program.cs");
|
var fileToChange = Path.Combine(_app.SourceDirectory, "Program.cs");
|
||||||
var programCs = File.ReadAllText(fileToChange);
|
var programCs = File.ReadAllText(fileToChange);
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
private const string StartedMessage = "Started";
|
private const string StartedMessage = "Started";
|
||||||
private const string ExitingMessage = "Exiting";
|
private const string ExitingMessage = "Exiting";
|
||||||
private const string WatchExitedMessage = "watch : Exited";
|
private const string WatchExitedMessage = "watch : Exited";
|
||||||
|
private const string WaitingForFileChangeMessage = "watch : Waiting for a file to change";
|
||||||
|
|
||||||
private readonly ITestOutputHelper _logger;
|
private readonly ITestOutputHelper _logger;
|
||||||
private string _appName;
|
private string _appName;
|
||||||
|
|
@ -49,6 +50,11 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
||||||
await Process.GetOutputLineAsync(WatchExitedMessage, DefaultMessageTimeOut);
|
await Process.GetOutputLineAsync(WatchExitedMessage, DefaultMessageTimeOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task IsWaitingForFileChange()
|
||||||
|
{
|
||||||
|
await Process.GetOutputLineStartsWithAsync(WaitingForFileChangeMessage, DefaultMessageTimeOut);
|
||||||
|
}
|
||||||
|
|
||||||
public bool UsePollingWatcher { get; set; }
|
public bool UsePollingWatcher { get; set; }
|
||||||
|
|
||||||
public async Task<int> GetProcessId()
|
public async Task<int> GetProcessId()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue