未验证 提交 94e8b406 编写于 作者: J Jared Parsons 提交者: GitHub

Merge pull request #42966 from jaredpar/flaky

Fix EditorFeatures2 flakiness
......@@ -14,10 +14,13 @@
namespace Microsoft.CodeAnalysis.Editor.UnitTests
{
[Export(typeof(IExtensionErrorHandler))]
internal class TestExtensionErrorHandler : IExtensionErrorHandler
[Export(typeof(ITestErrorHandler))]
internal class TestExtensionErrorHandler : IExtensionErrorHandler, ITestErrorHandler
{
private ImmutableList<Exception> _exceptions = ImmutableList<Exception>.Empty;
public ImmutableList<Exception> Exceptions => _exceptions;
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public TestExtensionErrorHandler()
......@@ -27,12 +30,31 @@ public TestExtensionErrorHandler()
public void HandleError(object sender, Exception exception)
{
// Work around bug that is fixed in https://devdiv.visualstudio.com/DevDiv/_git/VS-Platform/pullrequest/209513
if (exception is NullReferenceException && exception.StackTrace.Contains("SpanTrackingWpfToolTipPresenter"))
if (exception is NullReferenceException &&
exception.StackTrace.Contains("SpanTrackingWpfToolTipPresenter"))
{
return;
}
// Work around for https://github.com/dotnet/roslyn/issues/42982
if (exception is NullReferenceException &&
exception.StackTrace.Contains("Microsoft.CodeAnalysis.Completion.Providers.AbstractEmbeddedLanguageCompletionProvider.GetLanguageProviders"))
{
return;
}
// Work around for https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1091056
if (exception is InvalidOperationException &&
exception.StackTrace.Contains("Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion.Implementation.CompletionTelemetryHost"))
{
return;
}
ExceptionUtilities.FailFast(exception);
// This exception is unexpected and as such we want the containing test case to
// fail. Unfortuntately throwing an exception here is not going to help because
// the editor is going to catch and swallow it. Store it here and wait for the
// containing workspace to notice it and throw.
_exceptions = _exceptions.Add(exception);
}
}
}
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Immutable;
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public interface ITestErrorHandler
{
/// <summary>
/// Records unexpected exceptions thrown during test executino that can't be immediately
/// reported.
/// </summary>
ImmutableList<Exception> Exceptions { get; }
}
}
......@@ -133,6 +133,15 @@ public override void After(MethodInfo methodUnderTest)
{
synchronizationContext.ThrowIfSwitchOccurred();
}
foreach (var testErrorHandler in exportProvider.GetExportedValues<ITestErrorHandler>())
{
var exceptions = testErrorHandler.Exceptions;
if (exceptions.Count > 0)
{
throw new AggregateException("Tests threw unexpected exceptions", exceptions);
}
}
}
}
finally
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册