Remove redundant calls to TimeoutAfter
This commit is contained in:
parent
97b9ff3b33
commit
71a11d5ed6
|
|
@ -14,8 +14,6 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
{
|
||||
public class GlobbingAppTests : IDisposable
|
||||
{
|
||||
private static readonly TimeSpan DefaultTimeout = TimeSpan.FromSeconds(30);
|
||||
|
||||
private GlobbingApp _app;
|
||||
public GlobbingAppTests(ITestOutputHelper logger)
|
||||
{
|
||||
|
|
@ -30,7 +28,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
_app.UsePollingWatcher = usePollingWatcher;
|
||||
await _app.StartWatcherAsync();
|
||||
|
||||
var types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
|
||||
var types = await _app.GetCompiledAppDefinedTypes();
|
||||
Assert.Equal(2, types);
|
||||
|
||||
var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
|
||||
|
|
@ -38,7 +36,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
File.WriteAllText(fileToChange, programCs);
|
||||
|
||||
await _app.HasRestarted();
|
||||
types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
|
||||
types = await _app.GetCompiledAppDefinedTypes();
|
||||
Assert.Equal(2, types);
|
||||
}
|
||||
|
||||
|
|
@ -47,14 +45,14 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
{
|
||||
await _app.StartWatcherAsync();
|
||||
|
||||
var types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
|
||||
var types = await _app.GetCompiledAppDefinedTypes();
|
||||
Assert.Equal(2, types);
|
||||
|
||||
var fileToChange = Path.Combine(_app.SourceDirectory, "include", "Foo.cs");
|
||||
File.Delete(fileToChange);
|
||||
|
||||
await _app.HasRestarted();
|
||||
types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
|
||||
types = await _app.GetCompiledAppDefinedTypes();
|
||||
Assert.Equal(1, types);
|
||||
}
|
||||
|
||||
|
|
@ -63,14 +61,14 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
{
|
||||
await _app.StartWatcherAsync();
|
||||
|
||||
var types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
|
||||
var types = await _app.GetCompiledAppDefinedTypes();
|
||||
Assert.Equal(2, types);
|
||||
|
||||
var folderToDelete = Path.Combine(_app.SourceDirectory, "include");
|
||||
Directory.Delete(folderToDelete, recursive: true);
|
||||
|
||||
await _app.HasRestarted();
|
||||
types = await _app.GetCompiledAppDefinedTypes().TimeoutAfter(DefaultTimeout);
|
||||
types = await _app.GetCompiledAppDefinedTypes();
|
||||
Assert.Equal(1, types);
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +129,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
|
||||
public async Task<int> GetCompiledAppDefinedTypes()
|
||||
{
|
||||
var definedTypesMessage = await Process.GetOutputLineAsync(m => m.StartsWith("Defined types = "));
|
||||
var definedTypesMessage = await Process.GetOutputLineAsync(m => m.StartsWith("Defined types = ")).TimeoutAfter(TimeSpan.FromSeconds(30));
|
||||
return int.Parse(definedTypesMessage.Split('=').Last());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
public async Task RestartProcessOnFileChange()
|
||||
{
|
||||
await _app.StartWatcherAsync(new[] { "--no-exit" });
|
||||
var pid = await _app.GetProcessId().TimeoutAfter(DefaultTimeout);
|
||||
var pid = await _app.GetProcessId();
|
||||
|
||||
// Then wait for it to restart when we change a file
|
||||
var fileToChange = Path.Combine(_app.SourceDirectory, "Program.cs");
|
||||
|
|
@ -34,7 +34,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
File.WriteAllText(fileToChange, programCs);
|
||||
|
||||
await _app.HasRestarted();
|
||||
var pid2 = await _app.GetProcessId().TimeoutAfter(DefaultTimeout);
|
||||
var pid2 = await _app.GetProcessId();
|
||||
Assert.NotEqual(pid, pid2);
|
||||
|
||||
// first app should have shut down
|
||||
|
|
@ -45,17 +45,17 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
public async Task RestartProcessThatTerminatesAfterFileChange()
|
||||
{
|
||||
await _app.StartWatcherAsync();
|
||||
var pid = await _app.GetProcessId().TimeoutAfter(DefaultTimeout);
|
||||
await _app.HasExited().TimeoutAfter(DefaultTimeout); // process should exit after run
|
||||
var pid = await _app.GetProcessId();
|
||||
await _app.HasExited(); // process should exit after run
|
||||
|
||||
var fileToChange = Path.Combine(_app.SourceDirectory, "Program.cs");
|
||||
var programCs = File.ReadAllText(fileToChange);
|
||||
File.WriteAllText(fileToChange, programCs);
|
||||
|
||||
await _app.HasRestarted();
|
||||
var pid2 = await _app.GetProcessId().TimeoutAfter(DefaultTimeout);
|
||||
var pid2 = await _app.GetProcessId();
|
||||
Assert.NotEqual(pid, pid2);
|
||||
await _app.HasExited().TimeoutAfter(DefaultTimeout); // process should exit after run
|
||||
await _app.HasExited(); // process should exit after run
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
{
|
||||
public class WatchableApp : IDisposable
|
||||
{
|
||||
private static readonly TimeSpan DefaultMessageTimeOut = TimeSpan.FromSeconds(30);
|
||||
|
||||
private const string StartedMessage = "Started";
|
||||
private const string ExitingMessage = "Exiting";
|
||||
|
||||
|
|
@ -39,16 +41,16 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
|
|||
public string SourceDirectory { get; }
|
||||
|
||||
public Task HasRestarted()
|
||||
=> Process.GetOutputLineAsync(StartedMessage).TimeoutAfter(TimeSpan.FromMinutes(2));
|
||||
=> Process.GetOutputLineAsync(StartedMessage).TimeoutAfter(DefaultMessageTimeOut);
|
||||
|
||||
public Task HasExited()
|
||||
=> Process.GetOutputLineAsync(ExitingMessage);
|
||||
=> Process.GetOutputLineAsync(ExitingMessage).TimeoutAfter(DefaultMessageTimeOut);
|
||||
|
||||
public bool UsePollingWatcher { get; set; }
|
||||
|
||||
public async Task<int> GetProcessId()
|
||||
{
|
||||
var line = await Process.GetOutputLineAsync(l => l.StartsWith("PID ="));
|
||||
var line = await Process.GetOutputLineAsync(l => l.StartsWith("PID =")).TimeoutAfter(DefaultMessageTimeOut);
|
||||
var pid = line.Split('=').Last();
|
||||
return int.Parse(pid);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue