diff --git a/src/SignalR/common/testassets/Tests.Utils/VerifyNoErrorsScope.cs b/src/SignalR/common/testassets/Tests.Utils/VerifyNoErrorsScope.cs index c66862fedc..511ab8bd1c 100644 --- a/src/SignalR/common/testassets/Tests.Utils/VerifyNoErrorsScope.cs +++ b/src/SignalR/common/testassets/Tests.Utils/VerifyNoErrorsScope.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -34,6 +34,32 @@ namespace Microsoft.AspNetCore.SignalR.Tests var results = _sink.GetLogs().Where(w => w.Write.LogLevel >= LogLevel.Error).ToList(); +#if NETCOREAPP2_1 || NETCOREAPP2_2 || NET461 + // -- Remove this code after 2.2 -- + // This section of code is resolving test flakiness caused by a race in LongPolling + // The race has been resolved in version 3.0 + // The below code tries to find is a DELETE request has arrived from the client before removing error logs associated with the race + // We do this because we don't want to hide any actual issues, but we feel confident that looking for DELETE first wont hide any real problems + var foundDelete = false; + var allLogs = _sink.GetLogs(); + foreach (var log in allLogs) + { + if (foundDelete == false && log.Write.Message.Contains("Request starting") && log.Write.Message.Contains("DELETE")) + { + foundDelete = true; + } + + if (foundDelete) + { + if ((log.Write.EventId.Name == "LongPollingTerminated" || log.Write.EventId.Name == "ApplicationError" || log.Write.EventId.Name == "FailedDispose") + && log.Write.Exception?.Message.Contains("Reading is not allowed after reader was completed.") == true) + { + results.Remove(log); + } + } + } +#endif + if (_expectedErrorsFilter != null) { results = results.Where(w => !_expectedErrorsFilter(w.Write)).ToList(); @@ -64,4 +90,4 @@ namespace Microsoft.AspNetCore.SignalR.Tests } } } -} \ No newline at end of file +}