Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test flaky tests #64617

Closed
wants to merge 18 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ private async Task ComputeAnalyzerSyntaxDiagnosticsAsync(AnalysisScope analysisS
var pendingAnalyzers = _analysisResultBuilder.GetPendingAnalyzers(analysisScope.Analyzers);
if (pendingAnalyzers.Length > 0)
{
Console.WriteLine("has pending analyzers");
var pendingAnalysisScope = pendingAnalyzers.Length < analysisScope.Analyzers.Length ? analysisScope.WithAnalyzers(pendingAnalyzers, hasAllAnalyzers: false) : analysisScope;

// Compute the analyzer diagnostics for the pending analysis scope.
Expand Down Expand Up @@ -1027,6 +1028,7 @@ private async Task ComputeAnalyzerDiagnosticsCoreAsync(AnalyzerDriver driver, As
{
try
{
Console.WriteLine("has pending syntax analysis");
// Perform analysis to compute new diagnostics.
Debug.Assert(!eventQueue.IsCompleted);
await driver.AttachQueueAndProcessAllEventsAsync(eventQueue, analysisScope, _analysisState, cancellationToken: cancellationToken).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected static string GetMarkup(string source, LanguageVersion languageVersion
</Workspace>";

protected override TestWorkspace CreateWorkspace(string fileContents)
=> TestWorkspace.CreateCSharp(fileContents, exportProvider: ExportProvider);
=> TestWorkspace.CreateCSharp(fileContents, composition: GetComposition());

internal override CompletionService GetCompletionService(Project project)
=> Assert.IsType<CSharpCompletionService>(base.GetCompletionService(project));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionPr
public abstract class AbstractInteractiveCSharpCompletionProviderTests : AbstractCSharpCompletionProviderTests<InteractiveCSharpTestWorkspaceFixture>
{
protected override TestWorkspace CreateWorkspace(string fileContents)
=> InteractiveCSharpTestWorkspaceFixture.CreateInteractiveWorkspace(fileContents, exportProvider: ExportProvider);
=> InteractiveCSharpTestWorkspaceFixture.CreateInteractiveWorkspace(fileContents, composition: GetComposition());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public async Task CrefCompletionSpeculatesOutsideTrivia()
class C
{
}";
using var workspace = TestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text }, exportProvider: ExportProvider);
using var workspace = TestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text }, composition: GetComposition());
var called = false;

var hostDocument = workspace.DocumentWithCursor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ public async Task Parameter13()
{
using var workspaceFixture = GetOrCreateWorkspaceFixture();

var workspace = workspaceFixture.Target.GetWorkspace(ExportProvider);
var workspace = workspaceFixture.Target.GetWorkspace(GetComposition());

var options = new CompletionOptions()
{
Expand Down Expand Up @@ -2340,7 +2340,7 @@ public async Task CustomNamingStyleInsideClass()
{
using var workspaceFixture = GetOrCreateWorkspaceFixture();

var workspace = workspaceFixture.Target.GetWorkspace(ExportProvider);
var workspace = workspaceFixture.Target.GetWorkspace(GetComposition());

var options = new CompletionOptions()
{
Expand Down Expand Up @@ -2368,7 +2368,7 @@ public async Task CustomNamingStyleInsideMethod()
{
using var workspaceFixture = GetOrCreateWorkspaceFixture();

var workspace = workspaceFixture.Target.GetWorkspace(ExportProvider);
var workspace = workspaceFixture.Target.GetWorkspace(GetComposition());

var options = new CompletionOptions()
{
Expand Down Expand Up @@ -2784,7 +2784,7 @@ public async Task ConflictingLocalVariable()
{
using var workspaceFixture = GetOrCreateWorkspaceFixture();

var workspace = workspaceFixture.Target.GetWorkspace(ExportProvider);
var workspace = workspaceFixture.Target.GetWorkspace(GetComposition());

var options = new CompletionOptions()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ void goo()
}
}";

using var workspace = TestWorkspace.CreateCSharp(markup, exportProvider: ExportProvider);
using var workspace = TestWorkspace.CreateCSharp(markup, composition: GetComposition());
var hostDocument = workspace.Documents.Single();
var position = hostDocument.CursorPosition.Value;
var document = workspace.CurrentSolution.GetDocument(hostDocument.Id);
Expand Down Expand Up @@ -1187,7 +1187,7 @@ static void Main(string[] args)

private async Task VerifyExclusiveAsync(string markup, bool exclusive)
{
using var workspace = TestWorkspace.CreateCSharp(markup, exportProvider: ExportProvider);
using var workspace = TestWorkspace.CreateCSharp(markup, composition: GetComposition());
var hostDocument = workspace.Documents.Single();
var position = hostDocument.CursorPosition.Value;
var document = workspace.CurrentSolution.GetDocument(hostDocument.Id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@ public override void set_Bar(int bay, int value)

</Workspace>", LanguageNames.CSharp, csharpFile, LanguageNames.VisualBasic, vbFile);

using var testWorkspace = TestWorkspace.Create(xmlString, exportProvider: ExportProvider);
using var testWorkspace = TestWorkspace.Create(xmlString, composition: GetComposition());
var testDocument = testWorkspace.Documents.Single(d => d.Name == "CSharpDocument");

Contract.ThrowIfNull(testDocument.CursorPosition);
Expand Down Expand Up @@ -2620,7 +2620,7 @@ public override bool Equals(object obj)
</Project>
</Workspace>", LanguageNames.CSharp, file1, file2);

using var testWorkspace = TestWorkspace.Create(xmlString, exportProvider: ExportProvider);
using var testWorkspace = TestWorkspace.Create(xmlString, composition: GetComposition());
var testDocument = testWorkspace.Documents.Single(d => d.Name == "CSharpDocument2");

Contract.ThrowIfNull(testDocument.CursorPosition);
Expand Down Expand Up @@ -2676,7 +2676,7 @@ public override bool Equals(object obj)
</Project>
</Workspace>", LanguageNames.CSharp, file2, file1);

using var testWorkspace = TestWorkspace.Create(xmlString, exportProvider: ExportProvider);
using var testWorkspace = TestWorkspace.Create(xmlString, composition: GetComposition());
var testDocument = testWorkspace.Documents.Single(d => d.Name == "CSharpDocument");

Contract.ThrowIfNull(testDocument.CursorPosition);
Expand Down Expand Up @@ -2963,7 +2963,7 @@ static void Main(string[] args)
override $$
}
}";
using var workspace = TestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text }, exportProvider: ExportProvider);
using var workspace = TestWorkspace.Create(LanguageNames.CSharp, new CSharpCompilationOptions(OutputKind.ConsoleApplication), new CSharpParseOptions(), new[] { text }, composition: GetComposition());
var provider = new OverrideCompletionProvider();
var testDocument = workspace.Documents.Single();
var document = workspace.CurrentSolution.GetRequiredDocument(testDocument.Id);
Expand Down Expand Up @@ -3091,7 +3091,7 @@ public virtual void Bar() {}
// P1 has a metadata reference to P3 and therefore doesn't get the transitive
// reference to P2. If we try to override Goo, the missing "Missing" type will
// prevent round tripping the symbolkey.
using var workspace = TestWorkspace.Create(text, exportProvider: ExportProvider);
using var workspace = TestWorkspace.Create(text, composition: GetComposition());
var compilation = await workspace.CurrentSolution.Projects.First(p => p.Name == "P3").GetCompilationAsync();

// CompilationExtensions is in the Microsoft.CodeAnalysis.Test.Utilities namespace
Expand Down Expand Up @@ -3129,7 +3129,7 @@ public class SomeClass : Base
</Project>
</Workspace>");

using var workspace = TestWorkspace.Create(source, exportProvider: ExportProvider);
using var workspace = TestWorkspace.Create(source, composition: GetComposition());
var before = @"
public abstract class Base
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ public async Task ExpressionBodyMethod()
{
using var workspaceFixture = GetOrCreateWorkspaceFixture();

var workspace = workspaceFixture.Target.GetWorkspace(ExportProvider);
var workspace = workspaceFixture.Target.GetWorkspace(GetComposition());
workspace.GlobalOptions.SetGlobalOption(
new OptionKey(CSharpCodeStyleOptions.PreferExpressionBodiedMethods),
new CodeStyleOption2<ExpressionBodyPreference>(ExpressionBodyPreference.WhenPossible, NotificationOption2.Silent));
Expand Down Expand Up @@ -810,7 +810,7 @@ public async Task ExpressionBodyMethodExtended()
{
using var workspaceFixture = GetOrCreateWorkspaceFixture();

var workspace = workspaceFixture.Target.GetWorkspace(ExportProvider);
var workspace = workspaceFixture.Target.GetWorkspace(GetComposition());
workspace.GlobalOptions.SetGlobalOption(
new OptionKey(CSharpCodeStyleOptions.PreferExpressionBodiedMethods),
new CodeStyleOption2<ExpressionBodyPreference>(ExpressionBodyPreference.WhenPossible, NotificationOption2.Silent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ private async Task VerifyWorkerAsync(string markup, bool isBuilder)

using (var workspaceFixture = new CSharpTestWorkspaceFixture())
{
workspaceFixture.GetWorkspace(ExportProvider);
workspaceFixture.GetWorkspace(GetComposition());
var document1 = workspaceFixture.UpdateDocument(code, SourceCodeKind.Regular);
await CheckResultsAsync(document1, position, isBuilder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public static void Main()
var experimental = TestOptions.Regular.WithFeatures(featuresToEnable);

using var workspace = TestWorkspace.CreateCSharp(
source1, parseOptions: experimental, compilationOptions: null, exportProvider: null);
source1, parseOptions: experimental, compilationOptions: null);

var oldSolution = workspace.CurrentSolution;
var oldProject = oldSolution.Projects.Single();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public class InteractiveNavigateToTests : AbstractNavigateToTests
{
protected override string Language => "csharp";

protected override TestWorkspace CreateWorkspace(string content, ExportProvider exportProvider)
=> TestWorkspace.CreateCSharp(content, parseOptions: Options.Script, exportProvider: exportProvider);
protected override TestWorkspace CreateWorkspace(string content, TestComposition composition)
=> TestWorkspace.CreateCSharp(content, parseOptions: Options.Script, composition: composition);

[WpfTheory]
[CombinatorialData]
Expand Down
4 changes: 2 additions & 2 deletions src/EditorFeatures/CSharpTest/NavigateTo/NavigateToTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class NavigateToTests : AbstractNavigateToTests
{
protected override string Language => "csharp";

protected override TestWorkspace CreateWorkspace(string content, ExportProvider exportProvider)
=> TestWorkspace.CreateCSharp(content, exportProvider: exportProvider);
protected override TestWorkspace CreateWorkspace(string content, TestComposition composition)
=> TestWorkspace.CreateCSharp(content, composition: composition);

[Theory]
[CombinatorialData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private static TestWorkspace CreateWorkspace(
TestComposition composition = null)
{
composition ??= EditorTestCompositions.EditorFeatures;
return new TestWorkspace(exportProvider: null, composition, workspaceKind, disablePartialSolutions: disablePartialSolutions);
return new TestWorkspace(composition, workspaceKind, disablePartialSolutions: disablePartialSolutions);
}

private static async Task WaitForWorkspaceOperationsToComplete(TestWorkspace workspace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ protected static async Task<Tuple<Solution, Solution>> TestOperationsAsync(
if (TestWorkspace.IsWorkspaceElement(expectedText))
{
var newSolutionWithLinkedFiles = await newSolution.WithMergedLinkedFileChangesAsync(oldSolution);
await VerifyAgainstWorkspaceDefinitionAsync(expectedText, newSolutionWithLinkedFiles, workspace.ExportProvider);
await VerifyAgainstWorkspaceDefinitionAsync(expectedText, newSolutionWithLinkedFiles, workspace.Composition);
return Tuple.Create(oldSolution, newSolution);
}

Expand Down Expand Up @@ -661,9 +661,9 @@ protected static Document GetDocumentToVerify(DocumentId expectedChangedDocument
return document;
}

private static async Task VerifyAgainstWorkspaceDefinitionAsync(string expectedText, Solution newSolution, ExportProvider exportProvider)
private static async Task VerifyAgainstWorkspaceDefinitionAsync(string expectedText, Solution newSolution, TestComposition composition)
{
using (var expectedWorkspace = TestWorkspace.Create(expectedText, exportProvider: exportProvider))
using (var expectedWorkspace = TestWorkspace.Create(expectedText, composition: composition))
{
var expectedSolution = expectedWorkspace.CurrentSolution;
Assert.Equal(expectedSolution.Projects.Count(), newSolution.Projects.Count());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
using Microsoft.CodeAnalysis.Diagnostics.EngineV2;
using Microsoft.CodeAnalysis.Editor.Test;
using Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.LanguageServer;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Remote.Diagnostics;
Expand Down Expand Up @@ -868,19 +870,17 @@ void M()
sourceGeneratedFiles = Array.Empty<string>();
}

using var workspace = TestWorkspace.CreateCSharp(files, sourceGeneratedFiles,
composition: s_editorFeaturesCompositionWithMockDiagnosticUpdateSourceRegistrationService.AddParts(
typeof(TestDocumentTrackingService),
typeof(TestWorkspaceConfigurationService)));
var composition = s_editorFeaturesCompositionWithMockDiagnosticUpdateSourceRegistrationService.AddParts(
typeof(TestDocumentTrackingService));

var workspaceConfigurationService = workspace.GetService<TestWorkspaceConfigurationService>();
workspaceConfigurationService.Options = new(EnableOpeningSourceGeneratedFiles: true);
using var workspace = new TestWorkspace(composition, configurationOptions: new WorkspaceConfigurationOptions(EnableOpeningSourceGeneratedFiles: true));

workspace.GlobalOptions.SetGlobalOption(new OptionKey(SolutionCrawlerOptionsStorage.BackgroundAnalysisScopeOption, LanguageNames.CSharp), analysisScope);

var compilerDiagnosticsScope = analysisScope.ToEquivalentCompilerDiagnosticsScope();
workspace.GlobalOptions.SetGlobalOption(new OptionKey(SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption, LanguageNames.CSharp), compilerDiagnosticsScope);

workspace.InitializeDocuments(TestWorkspace.CreateWorkspaceElement(LanguageNames.CSharp, files: files, sourceGeneratedFiles: sourceGeneratedFiles), openDocuments: false);
workspace.TryApplyChanges(workspace.CurrentSolution.WithAnalyzerReferences(new[] { analyzerReference }));

var project = workspace.CurrentSolution.Projects.Single();
Expand Down
Loading