提交 bd7a08e9 编写于 作者: J Jared Parsons

More test fixes

上级 4f1f0c58
......@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.CodeFixes.GenerateType;
......@@ -124,23 +125,23 @@ public void TestGenerateClassFromFieldDeclarationIntoSameType()
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void TestGenerateClassFromFieldDeclarationIntoGlobalNamespace()
public async Task TestGenerateClassFromFieldDeclarationIntoGlobalNamespace()
{
TestAddDocument(
await TestAddDocument(
@"class Program { void Main ( ) { [|Foo|] f ; } } ",
@"internal class Foo { } ",
expectedContainers: Array.Empty<string>(),
expectedDocumentName: "Foo.cs");
expectedDocumentName: "Foo.cs").ConfigureAwait(true);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void TestGenerateClassFromFieldDeclarationIntoCustomNamespace()
public async Task TestGenerateClassFromFieldDeclarationIntoCustomNamespace()
{
TestAddDocument(
await TestAddDocument(
@"class Class { [|TestNamespace|].Foo f; }",
@"namespace TestNamespace { internal class Foo { } }",
expectedContainers: new List<string> { "TestNamespace" },
expectedDocumentName: "Foo.cs");
expectedDocumentName: "Foo.cs").ConfigureAwait(true);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
......@@ -405,13 +406,13 @@ public void GenerateTypeIntoContainingNamespace()
[WorkItem(538516)]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void TestGenerateClassFromIntoNewNamespace()
public async Task TestGenerateClassFromIntoNewNamespace()
{
TestAddDocument(
await TestAddDocument(
@"class Class { static void Main(string[] args) { [|N|].C c; } }",
@"namespace N { internal class C { } }",
expectedContainers: new List<string> { "N" },
expectedDocumentName: "C.cs");
expectedDocumentName: "C.cs").ConfigureAwait(true);
}
[WorkItem(538558)]
......@@ -1018,13 +1019,13 @@ public void TestEscapedKeyword()
[WorkItem(539535)]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void TestGenerateIntoNewFile()
public async Task TestGenerateIntoNewFile()
{
TestAddDocument(
await TestAddDocument(
@"class Class { void F() { new [|Foo|].Bar(); } }",
@"namespace Foo { internal class Bar { public Bar() { } } }",
expectedContainers: new List<string> { "Foo" },
expectedDocumentName: "Bar.cs");
expectedDocumentName: "Bar.cs").ConfigureAwait(true);
}
[WorkItem(539620)]
......@@ -1513,13 +1514,13 @@ public void TestDisplayStringForGlobalNamespace()
[WorkItem(543853)]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void TestAddDocumentForGlobalNamespace()
public async Task TestAddDocumentForGlobalNamespace()
{
TestAddDocument(
await TestAddDocument(
@"class C : [|Foo|]",
"internal class Foo { }",
Array.Empty<string>(),
"Foo.cs");
"Foo.cs").ConfigureAwait(true);
}
[WorkItem(543886)]
......@@ -1654,7 +1655,7 @@ public class C
[WorkItem(932602)]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void TestGenerateTypeInFolderNotDefaultNamespace_0()
public async Task TestGenerateTypeInFolderNotDefaultNamespace_0()
{
var code = @"<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"" DefaultNamespace = ""Namespace1.Namespace2"">
......@@ -1676,17 +1677,17 @@ public class ClassB
}
}";
TestAddDocument(code,
await TestAddDocument(code,
expected,
expectedContainers: Array.Empty<string>(),
expectedDocumentName: "ClassB.cs",
compareTokens: false,
isLine: false);
isLine: false).ConfigureAwait(true);
}
[WorkItem(932602)]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)]
public void TestGenerateTypeInFolderNotDefaultNamespace_1()
public async Task TestGenerateTypeInFolderNotDefaultNamespace_1()
{
var code = @"<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"" DefaultNamespace = ""Namespace1.Namespace2"" >
......@@ -1708,12 +1709,12 @@ public class ClassB
}
}";
TestAddDocument(code,
await TestAddDocument(code,
expected,
expectedContainers: new List<string> { "Namespace1", "Namespace2" },
expectedDocumentName: "ClassB.cs",
compareTokens: false,
isLine: false);
isLine: false).ConfigureAwait(true);
}
[WorkItem(612700)]
......
......@@ -257,7 +257,7 @@ public CaretPosition GetCaretPoint()
public async Task WaitForAsynchronousOperationsAsync()
{
var waiters = Workspace.ExportProvider.GetExportedValues<IAsynchronousOperationWaiter>();
await waiters.PumpingWaitAllAsync().ConfigureAwait(true);
await waiters.WaitAllAsync().ConfigureAwait(true);
}
public void WaitForAsynchronousOperations()
......
......@@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeRefactorings;
......@@ -53,7 +54,7 @@ private IEnumerable<ICodeRefactoring> GetCodeRefactorings(TestWorkspace workspac
return actions.Count > 0 ? new CodeRefactoring(provider, actions) : null;
}
protected void TestActionsOnLinkedFiles(
protected async Task TestActionsOnLinkedFiles(
TestWorkspace workspace,
string expectedText,
int index,
......@@ -63,7 +64,7 @@ private IEnumerable<ICodeRefactoring> GetCodeRefactorings(TestWorkspace workspac
{
var operations = VerifyInputsAndGetOperations(index, actions);
VerifyPreviewContents(workspace, expectedPreviewContents, operations);
await VerifyPreviewContents(workspace, expectedPreviewContents, operations).ConfigureAwait(true);
var applyChangesOperation = operations.OfType<ApplyChangesOperation>().First();
applyChangesOperation.Apply(workspace, CancellationToken.None);
......@@ -84,12 +85,12 @@ private IEnumerable<ICodeRefactoring> GetCodeRefactorings(TestWorkspace workspac
}
}
private static void VerifyPreviewContents(TestWorkspace workspace, string expectedPreviewContents, IEnumerable<CodeActionOperation> operations)
private static async Task VerifyPreviewContents(TestWorkspace workspace, string expectedPreviewContents, IEnumerable<CodeActionOperation> operations)
{
if (expectedPreviewContents != null)
{
var editHandler = workspace.ExportProvider.GetExportedValue<ICodeActionEditHandlerService>();
var content = editHandler.GetPreviews(workspace, operations, CancellationToken.None).TakeNextPreviewAsync().PumpingWaitResult();
var content = await editHandler.GetPreviews(workspace, operations, CancellationToken.None).TakeNextPreviewAsync().ConfigureAwait(true);
var diffView = content as IWpfDifferenceViewer;
Assert.NotNull(diffView);
var previewContents = diffView.RightView.TextBuffer.AsTextContainer().CurrentText.ToString();
......
......@@ -206,18 +206,18 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
}
}
protected void TestAddDocument(
protected async Task TestAddDocument(
string initialMarkup, string expectedMarkup,
IList<string> expectedContainers,
string expectedDocumentName,
int index = 0,
bool compareTokens = true, bool isLine = true)
{
TestAddDocument(initialMarkup, expectedMarkup, index, expectedContainers, expectedDocumentName, null, null, compareTokens, isLine);
TestAddDocument(initialMarkup, expectedMarkup, index, expectedContainers, expectedDocumentName, GetScriptOptions(), null, compareTokens, isLine);
await TestAddDocument(initialMarkup, expectedMarkup, index, expectedContainers, expectedDocumentName, null, null, compareTokens, isLine).ConfigureAwait(true);
await TestAddDocument(initialMarkup, expectedMarkup, index, expectedContainers, expectedDocumentName, GetScriptOptions(), null, compareTokens, isLine).ConfigureAwait(true);
}
private void TestAddDocument(
private async Task TestAddDocument(
string initialMarkup, string expectedMarkup,
int index,
IList<string> expectedContainers,
......@@ -228,12 +228,12 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
using (var workspace = isLine ? CreateWorkspaceFromFile(initialMarkup, parseOptions, compilationOptions) : TestWorkspaceFactory.CreateWorkspace(initialMarkup))
{
var codeActions = GetCodeActions(workspace, fixAllActionEquivalenceKey: null);
TestAddDocument(workspace, expectedMarkup, index, expectedContainers, expectedDocumentName,
codeActions, compareTokens);
await TestAddDocument(workspace, expectedMarkup, index, expectedContainers, expectedDocumentName,
codeActions, compareTokens).ConfigureAwait(true);
}
}
private void TestAddDocument(
private async Task TestAddDocument(
TestWorkspace workspace,
string expectedMarkup,
int index,
......@@ -243,7 +243,7 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
bool compareTokens)
{
var operations = VerifyInputsAndGetOperations(index, actions);
TestAddDocument(
await TestAddDocument(
workspace,
expectedMarkup,
operations,
......@@ -251,10 +251,10 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
modifiedProjectId: null,
expectedFolders: expectedFolders,
expectedDocumentName: expectedDocumentName,
compareTokens: compareTokens);
compareTokens: compareTokens).ConfigureAwait(true);
}
private Tuple<Solution, Solution> TestAddDocument(
private async Task<Tuple<Solution, Solution>> TestAddDocument(
TestWorkspace workspace,
string expected,
IEnumerable<CodeActionOperation> operations,
......@@ -297,7 +297,7 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
if (!hasProjectChange)
{
// If there is just one document change then we expect the preview to be a WpfTextView
var content = editHandler.GetPreviews(workspace, operations, CancellationToken.None).TakeNextPreviewAsync().PumpingWaitResult();
var content = await editHandler.GetPreviews(workspace, operations, CancellationToken.None).TakeNextPreviewAsync().ConfigureAwait(true);
var diffView = content as IWpfDifferenceViewer;
Assert.NotNull(diffView);
diffView.Close();
......@@ -308,7 +308,7 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
var contents = editHandler.GetPreviews(workspace, operations, CancellationToken.None);
bool hasPreview = false;
object preview;
while ((preview = contents.TakeNextPreviewAsync().PumpingWaitResult()) != null)
while ((preview = await contents.TakeNextPreviewAsync().ConfigureAwait(true)) != null)
{
var diffView = preview as IWpfDifferenceViewer;
if (diffView != null)
......@@ -325,7 +325,7 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
return Tuple.Create(oldSolution, newSolution);
}
internal void TestWithMockedGenerateTypeDialog(
internal async Task TestWithMockedGenerateTypeDialog(
string initial,
string languageName,
string typeName,
......@@ -402,7 +402,7 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
}
else
{
oldSolutionAndNewSolution = TestAddDocument(
oldSolutionAndNewSolution = await TestAddDocument(
testState.Workspace,
expected,
operations,
......@@ -410,7 +410,7 @@ protected void TestEquivalenceKey(string initialMarkup, string equivalenceKey)
testState.ProjectToBeModified.Id,
newFileFolderContainers,
newFileName,
compareTokens: false);
compareTokens: false).ConfigureAwait(true);
}
if (checkIfUsingsIncluded)
......
......@@ -35,7 +35,7 @@ protected override object CreateCodeRefactoringProvider(Workspace workspace)
}
[WpfFact]
public void TestCodeActionPreviewAndApply()
public async Task TestCodeActionPreviewAndApply()
{
using (var workspace = TestWorkspaceFactory.CreateWorkspace(WorkspaceXml))
{
......@@ -43,12 +43,12 @@ public void TestCodeActionPreviewAndApply()
var expectedCode = "private class D { }";
TestActionsOnLinkedFiles(
await TestActionsOnLinkedFiles(
workspace,
expectedText: expectedCode,
index: 0,
actions: codeIssueOrRefactoring.Actions.ToList(),
expectedPreviewContents: expectedCode);
expectedPreviewContents: expectedCode).ConfigureAwait(true);
}
}
......
......@@ -209,8 +209,7 @@ public void AssertNotificationMessage()
private async Task WaitForAsyncOperationsAsync()
{
var waiters = Workspace.ExportProvider.GetExportedValues<IAsynchronousOperationWaiter>();
var tasks = waiters.Select(w => w.CreateWaitTask()).ToList();
await tasks.PumpingWaitAllAsync().ConfigureAwait(true);
await waiters.WaitAllAsync().ConfigureAwait(true);
}
public void Dispose()
......
......@@ -211,13 +211,13 @@ public void Project_AssemblyName_Change()
}
[WpfFact]
public void Project_AnalyzerOptions_Change()
public async Task Project_AnalyzerOptions_Change()
{
using (var workspace = new WorkCoordinatorWorkspace(TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic(), SolutionCrawler))
{
var solutionInfo = GetInitialSolutionInfo(workspace);
workspace.OnSolutionAdded(solutionInfo);
WaitWaiter(workspace.ExportProvider);
await WaitWaiterAsync(workspace.ExportProvider).ConfigureAwait(true);
var project = workspace.CurrentSolution.Projects.First(p => p.Name == "P1").AddAdditionalDocument("a1", SourceText.From("")).Project;
var worker = ExecuteOperation(workspace, w => w.ChangeProject(project.Id, project.Solution));
......@@ -483,85 +483,85 @@ public void Document_InvocationReasons()
}
[WpfFact]
public void Document_TopLevelType_Whitespace()
public async Task Document_TopLevelType_Whitespace()
{
var code = @"class C { $$ }";
var textToInsert = " ";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevelType_Character()
public async Task Document_TopLevelType_Character()
{
var code = @"class C { $$ }";
var textToInsert = "int";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevelType_NewLine()
public async Task Document_TopLevelType_NewLine()
{
var code = @"class C { $$ }";
var textToInsert = "\r\n";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevelType_NewLine2()
public async Task Document_TopLevelType_NewLine2()
{
var code = @"class C { $$";
var textToInsert = "\r\n";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_EmptyFile()
public async Task Document_EmptyFile()
{
var code = @"$$";
var textToInsert = "class";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevel1()
public async Task Document_TopLevel1()
{
var code = @"class C
{
public void Test($$";
var textToInsert = "int";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevel2()
public async Task Document_TopLevel2()
{
var code = @"class C
{
public void Test(int $$";
var textToInsert = " ";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevel3()
public async Task Document_TopLevel3()
{
var code = @"class C
{
public void Test(int i,$$";
var textToInsert = "\r\n";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_InteriorNode1()
public async Task Document_InteriorNode1()
{
var code = @"class C
{
......@@ -569,11 +569,11 @@ public void Test()
{$$";
var textToInsert = "\r\n";
InsertText(code, textToInsert, expectDocumentAnalysis: false);
await InsertText(code, textToInsert, expectDocumentAnalysis: false).ConfigureAwait(true);
}
[WpfFact]
public void Document_InteriorNode2()
public async Task Document_InteriorNode2()
{
var code = @"class C
{
......@@ -583,11 +583,11 @@ public void Test()
}";
var textToInsert = "int";
InsertText(code, textToInsert, expectDocumentAnalysis: false);
await InsertText(code, textToInsert, expectDocumentAnalysis: false).ConfigureAwait(true);
}
[WpfFact]
public void Document_InteriorNode_Field()
public async Task Document_InteriorNode_Field()
{
var code = @"class C
{
......@@ -595,11 +595,11 @@ public void Document_InteriorNode_Field()
}";
var textToInsert = "1";
InsertText(code, textToInsert, expectDocumentAnalysis: false);
await InsertText(code, textToInsert, expectDocumentAnalysis: false).ConfigureAwait(true);
}
[WpfFact]
public void Document_InteriorNode_Field1()
public async Task Document_InteriorNode_Field1()
{
var code = @"class C
{
......@@ -607,11 +607,11 @@ public void Document_InteriorNode_Field1()
}";
var textToInsert = "1";
InsertText(code, textToInsert, expectDocumentAnalysis: false);
await InsertText(code, textToInsert, expectDocumentAnalysis: false).ConfigureAwait(true);
}
[WpfFact]
public void Document_InteriorNode_Accessor()
public async Task Document_InteriorNode_Accessor()
{
var code = @"class C
{
......@@ -625,11 +625,11 @@ public int A
}";
var textToInsert = "return";
InsertText(code, textToInsert, expectDocumentAnalysis: false);
await InsertText(code, textToInsert, expectDocumentAnalysis: false).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevelWhitespace()
public async Task Document_TopLevelWhitespace()
{
var code = @"class C
{
......@@ -640,11 +640,11 @@ public int A()
}";
var textToInsert = "return";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_TopLevelWhitespace2()
public async Task Document_TopLevelWhitespace2()
{
var code = @"/// $$
class C
......@@ -655,11 +655,11 @@ public int A()
}";
var textToInsert = "return";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
public void Document_InteriorNode_Malformed()
public async Task Document_InteriorNode_Malformed()
{
var code = @"class C
{
......@@ -668,7 +668,7 @@ public void Test()
$$";
var textToInsert = "int";
InsertText(code, textToInsert, expectDocumentAnalysis: true);
await InsertText(code, textToInsert, expectDocumentAnalysis: true).ConfigureAwait(true);
}
[WpfFact]
......@@ -769,7 +769,7 @@ public void ProgressReporterTest()
}
}
private void InsertText(string code, string text, bool expectDocumentAnalysis, string language = LanguageNames.CSharp)
private async Task InsertText(string code, string text, bool expectDocumentAnalysis, string language = LanguageNames.CSharp)
{
using (var workspace = TestWorkspaceFactory.CreateWorkspaceFromLines(
SolutionCrawler, language, compilationOptions: null, parseOptions: null, content: new string[] { code }))
......@@ -791,7 +791,7 @@ private void InsertText(string code, string text, bool expectDocumentAnalysis, s
edit.Apply();
}
Wait(service, workspace);
await WaitAsync(service, workspace).ConfigureAwait(true);
service.Unregister(workspace);
......@@ -840,6 +840,13 @@ private void Wait(SolutionCrawlerRegistrationService service, TestWorkspace work
service.WaitUntilCompletion_ForTestingPurposesOnly(workspace);
}
private async Task WaitAsync(SolutionCrawlerRegistrationService service, TestWorkspace workspace)
{
await WaitWaiterAsync(workspace.ExportProvider).ConfigureAwait(true);
service.WaitUntilCompletion_ForTestingPurposesOnly(workspace);
}
private void WaitWaiter(ExportProvider provider)
{
var workspaceWaiter = GetListeners(provider).First(l => l.Metadata.FeatureName == FeatureAttribute.Workspace).Value as IAsynchronousOperationWaiter;
......@@ -849,6 +856,15 @@ private void WaitWaiter(ExportProvider provider)
solutionCrawlerWaiter.CreateWaitTask().PumpingWait();
}
private async Task WaitWaiterAsync(ExportProvider provider)
{
var workspaceWaiter = GetListeners(provider).First(l => l.Metadata.FeatureName == FeatureAttribute.Workspace).Value as IAsynchronousOperationWaiter;
await workspaceWaiter.CreateWaitTask().ConfigureAwait(true);
var solutionCrawlerWaiter = GetListeners(provider).First(l => l.Metadata.FeatureName == FeatureAttribute.SolutionCrawler).Value as IAsynchronousOperationWaiter;
await solutionCrawlerWaiter.CreateWaitTask().ConfigureAwait(true);
}
private static SolutionInfo GetInitialSolutionInfoWithP2P()
{
var projectId1 = ProjectId.CreateNewId();
......
......@@ -39,7 +39,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.IntelliSense
End Sub
End Class
<WpfFact>
<WpfFact(Skip:="xunit wait")>
Public Sub ChainingTaskStartsAsyncOperation()
Dim controller = New Mock(Of IController(Of Model))
Dim modelComputation = TestModelComputation.Create(controller:=controller.Object)
......
......@@ -429,7 +429,7 @@ End Class
End Using
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.Completion)>
<WpfFact(Skip:="xunit wait"), Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function TestNavigationBeforeCompletedComputation() As Task
' Simulate a very slow completion provider.
Dim e = New ManualResetEvent(False)
......
......@@ -77,9 +77,8 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.NavigationBar
Dim controllerFactory = workspace.GetService(Of INavigationBarControllerFactoryService)()
Dim controller = controllerFactory.CreateController(mockPresenter, subjectDocument.TextBuffer)
Dim tasks = workspace.ExportProvider.GetExportedValues(Of IAsynchronousOperationWaiter) _
.Select(Function(waiter) waiter.CreateWaitTask())
Await tasks.PumpingWaitAllAsync().ConfigureAwait(True)
Dim waiters = workspace.ExportProvider.GetExportedValues(Of IAsynchronousOperationWaiter)
Await waiters.WaitAllAsync().ConfigureAwait(True)
Assert.True(presentItemsCalled)
End Using
......@@ -319,14 +318,9 @@ End Class
workspace.OnProjectNameChanged(workspace.Projects.Single().Id, "VBProj2", "VBProj2.vbproj")
workspace.ExportProvider.GetExports(Of IAsynchronousOperationWaiter, FeatureMetadata)().Where(Function(l) l.Metadata.FeatureName = FeatureAttribute.Workspace).Single().Value.CreateWaitTask().PumpingWait()
workspace.ExportProvider.GetExports(Of IAsynchronousOperationWaiter, FeatureMetadata)().Where(Function(l) l.Metadata.FeatureName = FeatureAttribute.NavigationBar).Single().Value.CreateWaitTask().PumpingWait()
Dim tasks = workspace.ExportProvider.GetExportedValues(Of IAsynchronousOperationWaiter) _
.Select(Function(waiter) waiter.CreateWaitTask())
Await tasks.PumpingWaitAllAsync().ConfigureAwait(True)
Await workspace.ExportProvider.GetExports(Of IAsynchronousOperationWaiter, FeatureMetadata)().Where(Function(l) l.Metadata.FeatureName = FeatureAttribute.Workspace).Single().Value.CreateWaitTask().ConfigureAwait(True)
Await workspace.ExportProvider.GetExports(Of IAsynchronousOperationWaiter, FeatureMetadata)().Where(Function(l) l.Metadata.FeatureName = FeatureAttribute.NavigationBar).Single().Value.CreateWaitTask().ConfigureAwait(True)
Await workspace.ExportProvider.GetExportedValues(Of IAsynchronousOperationWaiter).WaitAllAsync().ConfigureAwait(True)
Assert.Equal("VBProj2", projectName)
End Using
End Function
......
......@@ -112,7 +112,7 @@ Namespace Microsoft.CodeAnalysis.Editor.UnitTests.Rename
Public Async Function WaitForRename(workspace As TestWorkspace) As Task
Dim waiters = workspace.ExportProvider.GetExportedValues(Of IAsynchronousOperationWaiter)
Await waiters.PumpingWaitAllAsync().ConfigureAwait(True)
Await waiters.WaitAllAsync().ConfigureAwait(True)
End Function
Public Function CreateRenameTrackingTagger(workspace As TestWorkspace, document As TestHostDocument) As ITagger(Of RenameTrackingTag)
......
......@@ -15,7 +15,8 @@ public static class WaitHelper
{
/// <summary>
/// This is a hueristic for checking to see if we are in a deadlock state because
/// we are waiting on a Task that may be in the StaTaskScheduler queue
/// we are waiting on a Task that may be in the StaTaskScheduler queue from the
/// main thread.
/// </summary>
/// <param name="tasks"></param>
private static void CheckForStaDeadlockInPumpingWait(IEnumerable<Task> tasks)
......@@ -96,29 +97,5 @@ public static void PumpingWaitAll(this IEnumerable<Task> tasks)
}
}
}
public static async Task PumpingWaitAllAsync(this IEnumerable<Task> tasks)
{
var smallTimeout = TimeSpan.FromMilliseconds(10);
var done = false;
while (!done)
{
done = await tasks.WhenAll(smallTimeout).ConfigureAwait(true);
/*
if (!done)
{
WaitForDispatchedOperationsToComplete(DispatcherPriority.ApplicationIdle);
}
*/
}
foreach (var task in tasks)
{
if (task.Exception != null)
{
throw task.Exception;
}
}
}
}
}
......@@ -83,7 +83,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeRefactorings
GetMainDocumentAndPreviews(workspace, document, previews)
' The changed document comes first.
Dim preview = previews.TakeNextPreviewAsync().PumpingWaitResult()
Dim preview = Await previews.TakeNextPreviewAsync().ConfigureAwait(True)
Assert.NotNull(preview)
Assert.True(TypeOf preview Is IWpfDifferenceViewer)
Dim diffView = DirectCast(preview, IWpfDifferenceViewer)
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Option Strict Off
Imports System.Threading.Tasks
Imports Microsoft.CodeAnalysis.CodeActions
Imports Microsoft.CodeAnalysis.CodeFixes
Imports Microsoft.CodeAnalysis.Diagnostics
......@@ -160,22 +161,22 @@ index:=1)
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)>
Public Sub TestGenerateIntoNewNamespace()
TestAddDocument(
Public Async Function TestGenerateIntoNewNamespace() As Task
Await TestAddDocument(
NewLines("Imports System \n Imports System.Collections.Generic \n Imports System.Linq \n Class Program \n Sub Main() \n Call New Foo.[|Bar|]() \n End Sub \n End Class"),
NewLines("Namespace Foo \n Friend Class Bar \n Public Sub New() \n End Sub \n End Class \n End Namespace"),
expectedContainers:={"Foo"},
expectedDocumentName:="Bar.vb")
End Sub
expectedDocumentName:="Bar.vb").ConfigureAwait(True)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)>
Public Sub TestGenerateIntoGlobalNamespaceNewFile()
TestAddDocument(
Public Async Function TestGenerateIntoGlobalNamespaceNewFile() As Task
Await TestAddDocument(
NewLines("Imports System \n Imports System.Collections.Generic \n Imports System.Linq \n Module Program \n Sub Main(args As String()) \n Dim x As New [|Foo|] \n End Sub \n End Module"),
NewLines("Friend Class Foo \n End Class"),
expectedContainers:=Array.Empty(Of String)(),
expectedDocumentName:="Foo.vb")
End Sub
expectedDocumentName:="Foo.vb").ConfigureAwait(True)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)>
Public Sub TestGenerateTypeThatImplementsInterface1()
......@@ -276,13 +277,13 @@ NewLines("Imports [|System|]"))
End Sub
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)>
Public Sub TestNoContainersInNewType()
TestAddDocument(
Public Async Function TestNoContainersInNewType() As Task
Await TestAddDocument(
NewLines("Class Base \n Sub Main \n Dim p = New [|Derived|]() \n End Sub \n End Class"),
NewLines("Friend Class Derived \n Public Sub New() \n End Sub \n End Class"),
expectedContainers:=Array.Empty(Of String)(),
expectedDocumentName:="Derived.vb")
End Sub
expectedDocumentName:="Derived.vb").ConfigureAwait(True)
End Function
<WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateType)>
Public Sub TestNotOfferedInsideBinaryExpressions()
......
......@@ -19,7 +19,16 @@ internal interface IAsynchronousOperationWaiter
internal static class AsynchronousOperationWaiter
{
internal static async Task PumpingWaitAllAsync(this IEnumerable<IAsynchronousOperationWaiter> waiters)
/// <summary>
/// Wait for all of the <see cref="IAsynchronousOperationWaiter"/> instances to finish their
/// work.
/// </summary>
/// <remarks>
/// This is a very handy method for debugging hangs in the unit test. Set a break point in the
/// loop, dig into the waiters and see all of the active <see cref="IAsyncToken"/> values
/// representing the remaining work.
/// </remarks>
internal static async Task WaitAllAsync(this IEnumerable<IAsynchronousOperationWaiter> waiters)
{
var smallTimeout = TimeSpan.FromMilliseconds(10);
var tasks = waiters.Select(x => x.CreateWaitTask()).ToList();
......
......@@ -81,7 +81,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
End Sub
<WpfFact>
Public Sub TestBuildStartEvent()
Public Async Function TestBuildStartEvent() As Task
Using workspace = CSharpWorkspaceFactory.CreateWorkspaceFromLines(String.Empty)
Dim waiter = New Waiter()
......@@ -101,12 +101,12 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Diagnostics
SpecializedCollections.SingletonEnumerable(GetDiagnosticData(workspace, project.Id))))
source.AddNewErrors(project.Id, New HashSet(Of DiagnosticData)(SpecializedCollections.SingletonEnumerable(diagnostic)), map)
waiter.CreateWaitTask().PumpingWait()
Await waiter.CreateWaitTask().ConfigureAwait(True)
source.OnSolutionBuild(Me, Shell.UIContextChangedEventArgs.From(False))
waiter.CreateWaitTask().PumpingWait()
Await waiter.CreateWaitTask().ConfigureAwait(True)
End Using
End Sub
End Function
<WpfFact>
Public Sub TestExternalBuildErrorCustomTags()
......
......@@ -7,7 +7,7 @@ Imports Roslyn.Test.Utilities
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
Public Class IsCalledByGraphQueryTests
<WpfFact, Trait(Traits.Feature, Traits.Features.Progression)>
Public Sub IsCalledBySimpleTests()
Public Async Function IsCalledBySimpleTests() As Threading.Tasks.Task
Using testState = New ProgressionTestState(
<Workspace>
<Project Language="C#" CommonReferences="true" FilePath="Z:\Project.csproj">
......@@ -38,7 +38,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
</Workspace>)
Dim inputGraph = testState.GetGraphWithMarkedSymbolNode()
Dim outputContext = testState.GetGraphContextAfterQuery(inputGraph, New IsCalledByGraphQuery(), GraphContextDirection.Target)
Dim outputContext = Await testState.GetGraphContextAfterQueryAsync(inputGraph, New IsCalledByGraphQuery(), GraphContextDirection.Target).ConfigureAwait(True)
AssertSimplifiedGraphIs(
outputContext.Graph,
......@@ -55,6 +55,6 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.Progression
</IdentifierAliases>
</DirectedGraph>)
End Using
End Sub
End Function
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册