Merge pull request #2090 from aspnet/release/2.1
Global suppress low impact logging verification in tests (#2089)
This commit is contained in:
commit
da94e984ce
|
|
@ -2,6 +2,8 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.WebSockets;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Testing;
|
||||
|
|
@ -11,22 +13,63 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
{
|
||||
public class VerifiableServerLoggedTest : VerifiableLoggedTest
|
||||
{
|
||||
private readonly Func<WriteContext, bool> _globalExpectedErrorsFilter;
|
||||
|
||||
public ServerFixture ServerFixture { get; }
|
||||
|
||||
public VerifiableServerLoggedTest(ServerFixture serverFixture, ITestOutputHelper output) : base(output)
|
||||
{
|
||||
ServerFixture = serverFixture;
|
||||
|
||||
_globalExpectedErrorsFilter = (writeContext) =>
|
||||
{
|
||||
// Suppress https://github.com/aspnet/SignalR/issues/2034
|
||||
if (writeContext.LoggerName == "Microsoft.AspNetCore.Http.Connections.Client.Internal.ServerSentEventsTransport" &&
|
||||
writeContext.Message.StartsWith("Error while sending to") &&
|
||||
writeContext.Exception is HttpRequestException)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Suppress https://github.com/aspnet/SignalR/issues/2069
|
||||
if (writeContext.LoggerName == "Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager" &&
|
||||
writeContext.Message.StartsWith("Failed disposing connection") &&
|
||||
writeContext.Exception is WebSocketException)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
private Func<WriteContext, bool> ResolveExpectedErrorsFilter(Func<WriteContext, bool> expectedErrorsFilter)
|
||||
{
|
||||
if (expectedErrorsFilter == null)
|
||||
{
|
||||
return _globalExpectedErrorsFilter;
|
||||
}
|
||||
|
||||
return (writeContext) =>
|
||||
{
|
||||
if (expectedErrorsFilter(writeContext))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return _globalExpectedErrorsFilter(writeContext);
|
||||
};
|
||||
}
|
||||
|
||||
public override IDisposable StartVerifableLog(out ILoggerFactory loggerFactory, LogLevel minLogLevel, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null)
|
||||
{
|
||||
var disposable = base.StartVerifableLog(out loggerFactory, minLogLevel, testName, expectedErrorsFilter);
|
||||
var disposable = base.StartVerifableLog(out loggerFactory, minLogLevel, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter));
|
||||
return new ServerLogScope(ServerFixture, loggerFactory, disposable);
|
||||
}
|
||||
|
||||
public override IDisposable StartVerifableLog(out ILoggerFactory loggerFactory, [CallerMemberName] string testName = null, Func<WriteContext, bool> expectedErrorsFilter = null)
|
||||
{
|
||||
var disposable = base.StartVerifableLog(out loggerFactory, testName, expectedErrorsFilter);
|
||||
var disposable = base.StartVerifableLog(out loggerFactory, testName, ResolveExpectedErrorsFilter(expectedErrorsFilter));
|
||||
return new ServerLogScope(ServerFixture, loggerFactory, disposable);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue