Fix tests on unix and make tests more reliable on all platforms
This commit is contained in:
parent
e054eac3bd
commit
cf465b2001
|
|
@ -37,6 +37,9 @@ namespace Microsoft.DotNet.Watcher.Core.Internal
|
|||
_pollingThread = new Thread(new ThreadStart(PollingLoop));
|
||||
_pollingThread.IsBackground = true;
|
||||
_pollingThread.Name = nameof(PollingFileWatcher);
|
||||
|
||||
CreateKnownFilesSnapshot();
|
||||
|
||||
_pollingThread.Start();
|
||||
}
|
||||
|
||||
|
|
@ -55,17 +58,6 @@ namespace Microsoft.DotNet.Watcher.Core.Internal
|
|||
set
|
||||
{
|
||||
EnsureNotDisposed();
|
||||
|
||||
if (value == true)
|
||||
{
|
||||
CreateKnownFilesSnapshot();
|
||||
|
||||
if (_pollingThread.ThreadState == System.Threading.ThreadState.Unstarted)
|
||||
{
|
||||
// Start the loop the first time events are enabled
|
||||
_pollingThread.Start();
|
||||
}
|
||||
}
|
||||
_raiseEvents = value;
|
||||
}
|
||||
}
|
||||
|
|
@ -124,6 +116,7 @@ namespace Microsoft.DotNet.Watcher.Core.Internal
|
|||
else
|
||||
{
|
||||
var fileMeta = _knownEntities[fullFilePath];
|
||||
|
||||
if (fileMeta.FileInfo.LastWriteTime != f.LastWriteTime)
|
||||
{
|
||||
// File changed
|
||||
|
|
|
|||
|
|
@ -4,20 +4,36 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static readonly int processId = Process.GetCurrentProcess().Id;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("AppWithDeps started.");
|
||||
ConsoleWrite("AppWithDeps started.");
|
||||
|
||||
var processId = Process.GetCurrentProcess().Id;
|
||||
File.AppendAllLines(args[0], new string[] { $"{processId}" });
|
||||
|
||||
File.WriteAllText(args[0] + ".started", "");
|
||||
Console.ReadLine();
|
||||
Block();
|
||||
}
|
||||
|
||||
private static void ConsoleWrite(string text)
|
||||
{
|
||||
Console.WriteLine($"[{processId}] {text}");
|
||||
}
|
||||
|
||||
private static void Block()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ConsoleWrite("Blocked...");
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,20 +4,36 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static readonly int processId = Process.GetCurrentProcess().Id;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("GlobbingApp started.");
|
||||
ConsoleWrite("GlobbingApp started.");
|
||||
|
||||
var processId = Process.GetCurrentProcess().Id;
|
||||
File.AppendAllLines(args[0], new string[] { $"{processId}" });
|
||||
|
||||
File.WriteAllText(args[0] + ".started", "");
|
||||
Console.ReadLine();
|
||||
Block();
|
||||
}
|
||||
|
||||
private static void ConsoleWrite(string text)
|
||||
{
|
||||
Console.WriteLine($"[{processId}] {text}");
|
||||
}
|
||||
|
||||
private static void Block()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ConsoleWrite("Blocked...");
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,23 +4,39 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace ConsoleApplication
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
private static readonly int processId = Process.GetCurrentProcess().Id;
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("NoDepsApp started.");
|
||||
ConsoleWrite("NoDepsApp started.");
|
||||
|
||||
var processId = Process.GetCurrentProcess().Id;
|
||||
File.AppendAllLines(args[0], new string[] { $"{processId}" });
|
||||
|
||||
File.WriteAllText(args[0] + ".started", "");
|
||||
|
||||
if (args.Length > 1 && args[1] == "--no-exit")
|
||||
{
|
||||
Console.ReadLine();
|
||||
Block();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConsoleWrite(string text)
|
||||
{
|
||||
Console.WriteLine($"[{processId}] {text}");
|
||||
}
|
||||
|
||||
private static void Block()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ConsoleWrite("Blocked...");
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
};
|
||||
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
|
||||
Thread.Sleep(1000);
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
|
||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||
|
|
@ -113,10 +117,8 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
});
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void FileInSubdirectory(bool usePolling)
|
||||
[Fact]
|
||||
public void FileInSubdirectory()
|
||||
{
|
||||
UsingTempDirectory(dir =>
|
||||
{
|
||||
|
|
@ -127,7 +129,7 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
|
||||
using (var changedEv = new ManualResetEvent(false))
|
||||
using (var watcher = FileWatcherFactory.CreateWatcher(dir, usePolling))
|
||||
using (var watcher = FileWatcherFactory.CreateWatcher(dir, true))
|
||||
{
|
||||
var filesChanged = new HashSet<string>();
|
||||
|
||||
|
|
@ -144,6 +146,10 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
};
|
||||
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
|
||||
Thread.Sleep(1000);
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
|
||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||
|
|
@ -169,6 +175,11 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
watcher.EnableRaisingEvents = false;
|
||||
|
||||
var testFileFullPath = Path.Combine(dir, "foo");
|
||||
|
||||
// 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);
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
|
||||
Assert.False(changedEv.WaitOne(DefaultTimeout / 2));
|
||||
|
|
@ -192,6 +203,11 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
}
|
||||
|
||||
var testFileFullPath = Path.Combine(dir, "foo");
|
||||
|
||||
// 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);
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
|
||||
Assert.False(changedEv.WaitOne(DefaultTimeout / 2));
|
||||
|
|
@ -226,6 +242,11 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
};
|
||||
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
|
||||
Thread.Sleep(1000);
|
||||
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
|
||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||
|
|
@ -253,24 +274,44 @@ namespace Microsoft.DotNet.Watcher.FunctionalTests
|
|||
};
|
||||
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
|
||||
Thread.Sleep(1000);
|
||||
|
||||
var testFileFullPath = Path.Combine(dir, "foo1");
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||
Assert.Equal(testFileFullPath, filesChanged.Single());
|
||||
filesChanged.Clear();
|
||||
|
||||
// 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);
|
||||
|
||||
testFileFullPath = Path.Combine(dir, "foo2");
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||
Assert.Equal(testFileFullPath, filesChanged.Single());
|
||||
filesChanged.Clear();
|
||||
|
||||
// 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);
|
||||
|
||||
testFileFullPath = Path.Combine(dir, "foo3");
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||
Assert.Equal(testFileFullPath, filesChanged.Single());
|
||||
filesChanged.Clear();
|
||||
|
||||
// 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);
|
||||
|
||||
File.WriteAllText(testFileFullPath, string.Empty);
|
||||
Assert.True(changedEv.WaitOne(DefaultTimeout));
|
||||
Assert.Equal(testFileFullPath, filesChanged.Single());
|
||||
|
|
|
|||
Loading…
Reference in New Issue