提交 2668181f 编写于 作者: C Cyrus Najmabadi

Make less blocking calls in tests.

上级 4dd79d38
......@@ -20,9 +20,9 @@ public TypeInferrerTests(CSharpTestWorkspaceFixture workspaceFixture) : base(wor
{
}
protected override void TestWorker(Document document, TextSpan textSpan, string expectedType, bool useNodeStartPosition)
protected override async Task TestWorkerAsync(Document document, TextSpan textSpan, string expectedType, bool useNodeStartPosition)
{
var root = document.GetSyntaxTreeAsync().Result.GetRoot();
var root = (await document.GetSyntaxTreeAsync()).GetRoot();
var node = FindExpressionSyntaxFromSpan(root, textSpan);
var typeInference = document.GetLanguageService<ITypeInferenceService>();
......
......@@ -57,15 +57,15 @@ protected async Task TestAsync(string text, string expectedType, bool testNode =
bool useNodeStartPosition)
{
var document = await fixture.UpdateDocumentAsync(text, SourceCodeKind.Regular);
TestWorker(document, textSpan, expectedType, useNodeStartPosition);
await TestWorkerAsync(document, textSpan, expectedType, useNodeStartPosition);
if (CanUseSpeculativeSemanticModel(document, textSpan.Start))
{
var document2 = await fixture.UpdateDocumentAsync(text, SourceCodeKind.Regular, cleanBeforeUpdate: false);
TestWorker(document2, textSpan, expectedType, useNodeStartPosition);
await TestWorkerAsync(document2, textSpan, expectedType, useNodeStartPosition);
}
}
protected abstract void TestWorker(Document document, TextSpan textSpan, string expectedType, bool useNodeStartPosition);
protected abstract Task TestWorkerAsync(Document document, TextSpan textSpan, string expectedType, bool useNodeStartPosition);
}
}
......@@ -16,7 +16,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.Outlining.Metadata
Dim workspace = Await TestWorkspaceFactory.CreateWorkspaceFromFilesAsync(WorkspaceKind.MetadataAsSource, LanguageNames.VisualBasic, Nothing, Nothing, fileContents)
Dim outliningService = workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService(Of IOutliningService)()
Dim document = workspace.CurrentSolution.Projects.Single().Documents.Single()
Dim actualOutliningSpans = outliningService.GetOutliningSpansAsync(document, CancellationToken.None).Result.Where(Function(s) s IsNot Nothing).ToArray()
Dim actualOutliningSpans = (Await outliningService.GetOutliningSpansAsync(document, CancellationToken.None)).Where(Function(s) s IsNot Nothing).ToArray()
Assert.Equal(expectedSpans.Length, actualOutliningSpans.Length)
For i As Integer = 0 To expectedSpans.Length - 1
......
......@@ -22,7 +22,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.QuickInfo
Return TestWithReferencesAsync(markup, Array.Empty(Of String)(), expectedResults)
End Function
Protected Sub TestShared(workspace As TestWorkspace, position As Integer, ParamArray expectedResults() As Action(Of Object))
Protected Async Function TestSharedAsync(workspace As TestWorkspace, position As Integer, ParamArray expectedResults() As Action(Of Object)) As Task
Dim noListeners = SpecializedCollections.EmptyEnumerable(Of Lazy(Of IAsynchronousOperationListener, FeatureMetadata))()
Dim provider = New SemanticQuickInfoProvider(
......@@ -34,7 +34,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.QuickInfo
workspace.GetService(Of IGlyphService),
workspace.GetService(Of ClassificationTypeMap))
TestShared(workspace, provider, position, expectedResults)
Await TestSharedAsync(workspace, provider, position, expectedResults)
' speculative semantic model
Dim document = workspace.CurrentSolution.Projects.First().Documents.First()
......@@ -45,13 +45,13 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.QuickInfo
edit.Apply()
End Using
TestShared(workspace, provider, position, expectedResults)
Await TestSharedAsync(workspace, provider, position, expectedResults)
End If
End Sub
End Function
Private Sub TestShared(workspace As TestWorkspace, provider As SemanticQuickInfoProvider, position As Integer, expectedResults() As Action(Of Object))
Dim state = provider.GetItemAsync(workspace.CurrentSolution.Projects.First().Documents.First(),
position, cancellationToken:=CancellationToken.None).Result
Private Async Function TestSharedAsync(workspace As TestWorkspace, provider As SemanticQuickInfoProvider, position As Integer, expectedResults() As Action(Of Object)) As Task
Dim state = Await provider.GetItemAsync(workspace.CurrentSolution.Projects.First().Documents.First(),
position, cancellationToken:=CancellationToken.None)
If state IsNot Nothing Then
WaitForDocumentationComment(state.Content)
......@@ -66,11 +66,11 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.QuickInfo
expected(state.Content)
Next
End If
End Sub
End Function
Protected Async Function TestFromXmlAsync(markup As String, ParamArray expectedResults As Action(Of Object)()) As Task
Using workspace = Await VisualBasicWorkspaceFactory.CreateWorkspaceAsync(markup)
TestShared(workspace, workspace.Documents.First().CursorPosition.Value, expectedResults)
Await TestSharedAsync(workspace, workspace.Documents.First().CursorPosition.Value, expectedResults)
End Using
End Function
......@@ -80,7 +80,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.QuickInfo
MarkupTestFile.GetPosition(markup, code, position)
Using workspace = Await VisualBasicWorkspaceFactory.CreateWorkspaceFromLinesAsync({code}, Nothing, metadataReferences)
TestShared(workspace, position, expectedResults)
Await TestSharedAsync(workspace, position, expectedResults)
End Using
End Function
......
......@@ -18,18 +18,18 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.TypeInferrer
MyBase.New(workspaceFixture)
End Sub
Protected Overrides Sub TestWorker(document As Document, textSpan As TextSpan, expectedType As String, useNodeStartPosition As Boolean)
Dim root = document.GetSyntaxTreeAsync().Result.GetRoot()
Protected Overrides Async Function TestWorkerAsync(document As Document, textSpan As TextSpan, expectedType As String, useNodeStartPosition As Boolean) As Task
Dim root = (Await document.GetSyntaxTreeAsync()).GetRoot()
Dim node = FindExpressionSyntaxFromSpan(root, textSpan)
Dim typeInference = document.GetLanguageService(Of ITypeInferenceService)()
Dim inferredType = If(
useNodeStartPosition,
typeInference.InferType(document.GetSemanticModelForSpanAsync(New TextSpan(node.SpanStart, 0), CancellationToken.None).Result, node.SpanStart, objectAsDefault:=True, cancellationToken:=CancellationToken.None),
typeInference.InferType(document.GetSemanticModelForSpanAsync(node.Span, CancellationToken.None).Result, node, objectAsDefault:=True, cancellationToken:=CancellationToken.None))
typeInference.InferType(Await document.GetSemanticModelForSpanAsync(New TextSpan(node.SpanStart, 0), CancellationToken.None), node.SpanStart, objectAsDefault:=True, cancellationToken:=CancellationToken.None),
typeInference.InferType(Await document.GetSemanticModelForSpanAsync(node.Span, CancellationToken.None), node, objectAsDefault:=True, cancellationToken:=CancellationToken.None))
Dim typeSyntax = inferredType.GenerateTypeSyntax().NormalizeWhitespace()
Assert.Equal(expectedType, typeSyntax.ToString())
End Sub
End Function
Private Async Function TestInClassAsync(text As String, expectedType As String) As Tasks.Task
text = <text>Class C
......
......@@ -466,7 +466,7 @@ End Sub"
code)
Dim hostDocument = workspace.DocumentWithCursor
Dim document As Document = workspace.CurrentSolution.GetDocument(hostDocument.Id)
Assert.Empty(document.GetSyntaxTreeAsync().Result.GetDiagnostics())
Assert.Empty((Await document.GetSyntaxTreeAsync()).GetDiagnostics())
Dim targetPosition = Await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
document,
hostDocument.CursorPosition.Value,
......@@ -487,7 +487,7 @@ End Sub"
code)
Dim hostDocument = workspace.DocumentWithCursor
Dim document As Document = workspace.CurrentSolution.GetDocument(hostDocument.Id)
Assert.Empty(document.GetSyntaxTreeAsync().Result.GetDiagnostics())
Assert.Empty((Await document.GetSyntaxTreeAsync()).GetDiagnostics())
Return Await GoToAdjacentMemberCommandHandler.GetTargetPositionAsync(
document,
hostDocument.CursorPosition.Value,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册