From 4e801ee7c163ec362000e72e9a687e00870f3543 Mon Sep 17 00:00:00 2001 From: Tomas Matousek Date: Thu, 14 Nov 2024 10:44:53 -0800 Subject: [PATCH] Fix race condition in test --- .../EditAndContinue/EditAndContinueWorkspaceTestBase.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Features/TestUtilities/EditAndContinue/EditAndContinueWorkspaceTestBase.cs b/src/Features/TestUtilities/EditAndContinue/EditAndContinueWorkspaceTestBase.cs index fc40635903865..eb6e9ac492dc2 100644 --- a/src/Features/TestUtilities/EditAndContinue/EditAndContinueWorkspaceTestBase.cs +++ b/src/Features/TestUtilities/EditAndContinue/EditAndContinueWorkspaceTestBase.cs @@ -54,13 +54,13 @@ public abstract class EditAndContinueWorkspaceTestBase : TestBase, IDisposable /// /// Streams that are verified to be disposed at the end of the debug session (by default). /// - public List<(Guid mvid, Stream stream)> DisposalVerifiedStreams = []; + private ImmutableList _disposalVerifiedStreams = []; public override void Dispose() { base.Dispose(); - foreach (var (_, stream) in DisposalVerifiedStreams) + foreach (var stream in _disposalVerifiedStreams) { Assert.False(stream.CanRead); } @@ -314,7 +314,7 @@ internal Guid EmitLibrary(Compilation compilation, DebugInformationFormat pdbFor OpenAssemblyStreamImpl = () => { var stream = new MemoryStream(); - DisposalVerifiedStreams.Add((moduleId, stream)); + ImmutableInterlocked.Update(ref _disposalVerifiedStreams, s => s.Add(stream)); peImage.WriteToStream(stream); stream.Position = 0; return stream; @@ -322,7 +322,7 @@ internal Guid EmitLibrary(Compilation compilation, DebugInformationFormat pdbFor OpenPdbStreamImpl = () => { var stream = new MemoryStream(); - DisposalVerifiedStreams.Add((moduleId, stream)); + ImmutableInterlocked.Update(ref _disposalVerifiedStreams, s => s.Add(stream)); pdbImage.WriteToStream(stream); stream.Position = 0; return stream;