Skip to content
代码片段 群组 项目
未验证 提交 7f4af095 编辑于 作者: Stephen Halter's avatar Stephen Halter 提交者: GitHub
浏览文件

Add timeout to all awaits in GlobbingAppTests (#23938)

上级 7b42cf12
No related branches found
No related tags found
无相关合并请求
......@@ -15,7 +15,10 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
{
public class GlobbingAppTests : IDisposable
{
private GlobbingApp _app;
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(60);
private readonly GlobbingApp _app;
public GlobbingAppTests(ITestOutputHelper logger)
{
_app = new GlobbingApp(logger);
......@@ -28,17 +31,17 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
public async Task ChangeCompiledFile(bool 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);
var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
var programCs = File.ReadAllText(fileToChange);
File.WriteAllText(fileToChange, programCs);
await _app.HasRestarted();
types = await _app.GetCompiledAppDefinedTypes();
await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
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")]
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);
var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
File.Delete(fileToChange);
await _app.HasRestarted();
types = await _app.GetCompiledAppDefinedTypes();
await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
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")]
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);
var folderToDelete = Path.Combine(_app.SourceDirectory, "include");
Directory.Delete(folderToDelete, recursive: true);
await _app.HasRestarted();
types = await _app.GetCompiledAppDefinedTypes();
await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
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")]
public async Task RenameCompiledFile()
{
await _app.StartWatcherAsync();
await _app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
var oldFile = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
var newFile = Path.Combine(_app.SourceDirectory, "include", "Foo_new.cs");
File.Move(oldFile, newFile);
await _app.HasRestarted();
await _app.HasRestarted().TimeoutAfter(DefaultTimeout);
}
[Fact]
public async Task ChangeExcludedFile()
{
await _app.StartWatcherAsync();
await _app.StartWatcherAsync().TimeoutAfter(DefaultTimeout);
var changedFile = Path.Combine(_app.SourceDirectory, "exclude", "Baz.cs");
File.WriteAllText(changedFile, "");
......@@ -105,11 +108,11 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
[Fact]
public async Task ListsFiles()
{
await _app.PrepareAsync();
await _app.PrepareAsync().TimeoutAfter(DefaultTimeout);
_app.Start(new[] { "--list" });
var cts = new CancellationTokenSource();
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 :"));
AssertEx.EqualFileList(
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册