Add timeout to all awaits in GlobbingAppTests (#23938)

This commit is contained in:
Stephen Halter 2020-07-15 18:52:37 -07:00 committed by GitHub
parent 7b42cf1275
commit 7f4af095f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 18 deletions

View File

@ -15,7 +15,10 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
{ {
public class GlobbingAppTests : IDisposable public class GlobbingAppTests : IDisposable
{ {
private GlobbingApp _app; private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(60);
private readonly GlobbingApp _app;
public GlobbingAppTests(ITestOutputHelper logger) public GlobbingAppTests(ITestOutputHelper logger)
{ {
_app = new GlobbingApp(logger); _app = new GlobbingApp(logger);
@ -28,17 +31,17 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
public async Task ChangeCompiledFile(bool usePollingWatcher) public async Task ChangeCompiledFile(bool usePollingWatcher)
{ {
_app.UsePollingWatcher = usePollingWatcher; _app.UsePollingWatcher = usePollingWatcher;
await _app.StartWatcherAsync(); await _app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
var types = await _app.GetCompiledAppDefinedTypes(); var types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
Assert.Equal(2, types); Assert.Equal(2, types);
var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs"); var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
var programCs = File.ReadAllText(fileToChange); var programCs = File.ReadAllText(fileToChange);
File.WriteAllText(fileToChange, programCs); File.WriteAllText(fileToChange, programCs);
await _app.HasRestarted(); await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await _app.GetCompiledAppDefinedTypes(); types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
Assert.Equal(2, types); Assert.Equal(2, types);
} }
@ -46,16 +49,16 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/23360", Queues = "Debian.9.Arm64;Debian.9.Arm64.Open;(Debian.9.Arm64.Open)Ubuntu.1804.Armarch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036;(Debian.9.Arm64)Ubuntu.1804.Armarch@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036")] [SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/23360", Queues = "Debian.9.Arm64;Debian.9.Arm64.Open;(Debian.9.Arm64.Open)Ubuntu.1804.Armarch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036;(Debian.9.Arm64)Ubuntu.1804.Armarch@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036")]
public async Task DeleteCompiledFile() public async Task DeleteCompiledFile()
{ {
await _app.StartWatcherAsync(); await _app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
var types = await _app.GetCompiledAppDefinedTypes(); var types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
Assert.Equal(2, types); Assert.Equal(2, types);
var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs"); var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
File.Delete(fileToChange); File.Delete(fileToChange);
await _app.HasRestarted(); await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await _app.GetCompiledAppDefinedTypes(); types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
Assert.Equal(1, types); Assert.Equal(1, types);
} }
@ -63,16 +66,16 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/23360", Queues = "Debian.9.Arm64;Debian.9.Arm64.Open;(Debian.9.Arm64.Open)Ubuntu.1804.Armarch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036;(Debian.9.Arm64)Ubuntu.1804.Armarch@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036")] [SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/23360", Queues = "Debian.9.Arm64;Debian.9.Arm64.Open;(Debian.9.Arm64.Open)Ubuntu.1804.Armarch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036;(Debian.9.Arm64)Ubuntu.1804.Armarch@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036")]
public async Task DeleteSourceFolder() public async Task DeleteSourceFolder()
{ {
await _app.StartWatcherAsync(); await _app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
var types = await _app.GetCompiledAppDefinedTypes(); var types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
Assert.Equal(2, types); Assert.Equal(2, types);
var folderToDelete = Path.Combine(_app.SourceDirectory, "include"); var folderToDelete = Path.Combine(_app.SourceDirectory, "include");
Directory.Delete(folderToDelete, recursive: true); Directory.Delete(folderToDelete, recursive: true);
await _app.HasRestarted(); await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await _app.GetCompiledAppDefinedTypes(); types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
Assert.Equal(1, types); Assert.Equal(1, types);
} }
@ -80,19 +83,19 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
[SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/23360", Queues = "Debian.9.Arm64;Debian.9.Arm64.Open;(Debian.9.Arm64.Open)Ubuntu.1804.Armarch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036;(Debian.9.Arm64)Ubuntu.1804.Armarch@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036")] [SkipOnHelix("https://github.com/dotnet/aspnetcore/issues/23360", Queues = "Debian.9.Arm64;Debian.9.Arm64.Open;(Debian.9.Arm64.Open)Ubuntu.1804.Armarch.Open@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036;(Debian.9.Arm64)Ubuntu.1804.Armarch@mcr.microsoft.com/dotnet-buildtools/prereqs:debian-9-helix-arm64v8-a12566d-20190807161036")]
public async Task RenameCompiledFile() public async Task RenameCompiledFile()
{ {
await _app.StartWatcherAsync(); await _app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
var oldFile = Path.Combine(_app.SourceDirectory, "include", "Foo.cs"); var oldFile = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
var newFile = Path.Combine(_app.SourceDirectory, "include", "Foo_new.cs"); var newFile = Path.Combine(_app.SourceDirectory, "include", "Foo_new.cs");
File.Move(oldFile, newFile); File.Move(oldFile, newFile);
await _app.HasRestarted(); await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
} }
[Fact] [Fact]
public async Task ChangeExcludedFile() public async Task ChangeExcludedFile()
{ {
await _app.StartWatcherAsync(); await _app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
var changedFile = Path.Combine(_app.SourceDirectory, "exclude", "Baz.cs"); var changedFile = Path.Combine(_app.SourceDirectory, "exclude", "Baz.cs");
File.WriteAllText(changedFile, ""); File.WriteAllText(changedFile, "");
@ -105,11 +108,11 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
[Fact] [Fact]
public async Task ListsFiles() public async Task ListsFiles()
{ {
await _app.PrepareAsync(); await _app.PrepareAsync().TimeoutAfter(DefaultTimeout);
_app.Start(new[] { "--list" }); _app.Start(new[] { "--list" });
var cts = new CancellationTokenSource(); var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(30)); cts.CancelAfter(TimeSpan.FromSeconds(30));
var lines = await _app.Process.GetAllOutputLinesAsync(cts.Token); var lines = await _app.Process.GetAllOutputLinesAsync(cts.Token).TimeoutAfter(DefaultTimeout);
var files = lines.Where(l => !l.StartsWith("watch :")); var files = lines.Where(l => !l.StartsWith("watch :"));
AssertEx.EqualFileList( AssertEx.EqualFileList(