capture wstest log output (#156)
This commit is contained in:
parent
214c41bf40
commit
eb0ab115d8
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
|
|||
|
||||
// Run the test (write something to the console so people know this will take a while...)
|
||||
_logger.LogInformation("Now launching Autobahn Test Suite. This will take a while.");
|
||||
var exitCode = await Wstest.Default.ExecAsync("-m fuzzingclient -s " + specFile, cancellationToken);
|
||||
var exitCode = await Wstest.Default.ExecAsync("-m fuzzingclient -s " + specFile, cancellationToken, _loggerFactory.CreateLogger("wstest"));
|
||||
if (exitCode != 0)
|
||||
{
|
||||
throw new Exception("wstest failed");
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.IO;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
|
||||
{
|
||||
|
|
@ -31,7 +32,7 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
|
|||
return null;
|
||||
}
|
||||
|
||||
public async Task<int> ExecAsync(string args, CancellationToken cancellationToken)
|
||||
public async Task<int> ExecAsync(string args, CancellationToken cancellationToken, ILogger logger)
|
||||
{
|
||||
var process = new Process()
|
||||
{
|
||||
|
|
@ -40,6 +41,8 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
|
|||
FileName = _path,
|
||||
Arguments = args,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true
|
||||
},
|
||||
EnableRaisingEvents = true
|
||||
};
|
||||
|
|
@ -48,13 +51,26 @@ namespace Microsoft.AspNetCore.WebSockets.ConformanceTest.Autobahn
|
|||
using (cancellationToken.Register(() => Cancel(process, tcs)))
|
||||
{
|
||||
process.Exited += (_, __) => tcs.TrySetResult(process.ExitCode);
|
||||
process.OutputDataReceived += (_, a) => LogIfNotNull(logger.LogInformation, "stdout: {0}", a.Data);
|
||||
process.ErrorDataReceived += (_, a) => LogIfNotNull(logger.LogError, "stderr: {0}", a.Data);
|
||||
|
||||
process.Start();
|
||||
|
||||
process.BeginErrorReadLine();
|
||||
process.BeginOutputReadLine();
|
||||
|
||||
return await tcs.Task;
|
||||
}
|
||||
}
|
||||
|
||||
private void LogIfNotNull(Action<string, object[]> logger, string message, string data)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(data))
|
||||
{
|
||||
logger(message, new[] { data });
|
||||
}
|
||||
}
|
||||
|
||||
private static void Cancel(Process process, TaskCompletionSource<int> tcs)
|
||||
{
|
||||
if (process != null && !process.HasExited)
|
||||
|
|
|
|||
Loading…
Reference in New Issue