Add more logging for flaky tests on CI (#393)

This commit is contained in:
Nate McMaster 2018-02-12 12:29:13 -08:00 committed by GitHub
parent f14799c4ae
commit d51a6951c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 11 deletions

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.Internal;
using Microsoft.Extensions.CommandLineUtils;
using Xunit.Abstractions;
@ -61,10 +62,19 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
_logger.WriteLine($"{DateTime.Now}: process start: '{_process.StartInfo.FileName} {_process.StartInfo.Arguments}'");
}
public Task<string> GetOutputLineAsync(string message)
=> GetOutputLineAsync(m => message == m);
public async Task<string> GetOutputLineAsync(string message, TimeSpan timeout)
{
_logger.WriteLine($"Waiting for output line [msg == '{message}']. Will wait for {timeout.TotalSeconds} sec.");
return await GetOutputLineAsync(m => message == m).TimeoutAfter(timeout);
}
public async Task<string> GetOutputLineAsync(Predicate<string> predicate)
public async Task<string> GetOutputLineStartsWithAsync(string message, TimeSpan timeout)
{
_logger.WriteLine($"Waiting for output line [msg.StartsWith('{message}')]. Will wait for {timeout.TotalSeconds} sec.");
return await GetOutputLineAsync(m => m.StartsWith(message)).TimeoutAfter(timeout);
}
private async Task<string> GetOutputLineAsync(Predicate<string> predicate)
{
while (!_source.Completion.IsCompleted)
{

View File

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
await _app.StartWatcherAsync();
const string messagePrefix = "DOTNET_WATCH = ";
var message = await _app.Process.GetOutputLineAsync(m => m.StartsWith(messagePrefix));
var message = await _app.Process.GetOutputLineStartsWithAsync(messagePrefix, TimeSpan.FromMinutes(2));
var envValue = message.Substring(messagePrefix.Length);
Assert.Equal("1", envValue);
}

View File

@ -5,7 +5,6 @@ using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Microsoft.DotNet.Watcher.Tools.Tests;
using Xunit;
using Xunit.Abstractions;
@ -129,7 +128,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
public async Task<int> GetCompiledAppDefinedTypes()
{
var definedTypesMessage = await Process.GetOutputLineAsync(m => m.StartsWith("Defined types = ")).TimeoutAfter(TimeSpan.FromSeconds(30));
var definedTypesMessage = await Process.GetOutputLineStartsWithAsync("Defined types = ", TimeSpan.FromSeconds(30));
return int.Parse(definedTypesMessage.Split('=').Last());
}
}

View File

@ -7,7 +7,6 @@ using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.CommandLineUtils;
using Xunit.Abstractions;
@ -41,16 +40,16 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
public string SourceDirectory { get; }
public Task HasRestarted()
=> Process.GetOutputLineAsync(StartedMessage).TimeoutAfter(DefaultMessageTimeOut);
=> Process.GetOutputLineAsync(StartedMessage, DefaultMessageTimeOut);
public Task HasExited()
=> Process.GetOutputLineAsync(ExitingMessage).TimeoutAfter(DefaultMessageTimeOut);
=> Process.GetOutputLineAsync(ExitingMessage, DefaultMessageTimeOut);
public bool UsePollingWatcher { get; set; }
public async Task<int> GetProcessId()
{
var line = await Process.GetOutputLineAsync(l => l.StartsWith("PID =")).TimeoutAfter(DefaultMessageTimeOut);
var line = await Process.GetOutputLineStartsWithAsync("PID =", DefaultMessageTimeOut);
var pid = line.Split('=').Last();
return int.Parse(pid);
}
@ -106,7 +105,7 @@ namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests
// Make this timeout long because it depends much on the MSBuild compilation speed.
// Slow machines may take a bit to compile and boot test apps
await Process.GetOutputLineAsync(StartedMessage).TimeoutAfter(TimeSpan.FromMinutes(2));
await Process.GetOutputLineAsync(StartedMessage, TimeSpan.FromMinutes(2));
}
public virtual void Dispose()