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

Make less blocking calls in tests.

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