Skip to content

Commit

Permalink
Fix race condition with multithreaded tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Jul 21, 2022
1 parent eb26f15 commit 579814f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/OmniSharp.Roslyn.CSharp.Tests/CompletionFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,12 @@ private OmniSharpTestHost GetImportCompletionHost()
{
var testHost = CreateOmniSharpHost(configurationData: new[] { new KeyValuePair<string, string>("RoslynExtensionsOptions:EnableImportCompletion", "true") });
testHost.AddFilesToWorkspace();
_completionFixture.ImportCompletionTestHost = testHost;
var result = Interlocked.CompareExchange(ref _completionFixture.ImportCompletionTestHost, testHost, null);
if (result != null)
{
testHost.Dispose();
testHost = result;
}
return testHost;
}
}
Expand All @@ -2319,7 +2324,12 @@ private OmniSharpTestHost GetAsyncCompletionAndImportCompletionHost()
new KeyValuePair<string, string>("RoslynExtensionsOptions:EnableAsyncCompletion", "true"),
});
testHost.AddFilesToWorkspace();
_completionFixture.ImportAndAsyncCompletionTestHost = testHost;
var result = Interlocked.CompareExchange(ref _completionFixture.ImportCompletionTestHost, testHost, null);
if (result != null)
{
testHost.Dispose();
testHost = result;
}
return testHost;
}
}
Expand Down Expand Up @@ -2352,8 +2362,8 @@ internal static class CompletionResponseExtensions
#nullable enable
public sealed class CompletionFixture : IDisposable
{
public OmniSharpTestHost? ImportCompletionTestHost { get; set; }
public OmniSharpTestHost? ImportAndAsyncCompletionTestHost { get; set; }
public OmniSharpTestHost? ImportCompletionTestHost;
public OmniSharpTestHost? ImportAndAsyncCompletionTestHost;

public void Dispose()
{
Expand Down

0 comments on commit 579814f

Please sign in to comment.