diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs index 6621259213815..6ac7a6b2a5599 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/BundledAppWithSubDirs.cs @@ -2,12 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Threading; +using System.Diagnostics; using BundleTests.Helpers; using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.CoreSetup.Test; using Microsoft.NET.HostModel.Bundle; using Xunit; +[assembly: CollectionBehavior(DisableTestParallelization = true)] + namespace AppHost.Bundle.Tests { public class BundledAppWithSubDirs : BundleTestBase, IClassFixture diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleAndRun.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleAndRun.cs index e4e5cc57c0897..3c75259da7c31 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleAndRun.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/Microsoft.NET.HostModel.Bundle.Tests/BundleAndRun.cs @@ -9,6 +9,8 @@ using BundleTests.Helpers; using System.Runtime.InteropServices; +[assembly: CollectionBehavior(DisableTestParallelization = true)] + namespace Microsoft.NET.HostModel.Tests { public class BundleAndRun : IClassFixture diff --git a/src/installer/tests/TestUtils/TestProjectFixture.cs b/src/installer/tests/TestUtils/TestProjectFixture.cs index 7b9da29d1a908..2da1541a8105b 100644 --- a/src/installer/tests/TestUtils/TestProjectFixture.cs +++ b/src/installer/tests/TestUtils/TestProjectFixture.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading; namespace Microsoft.DotNet.CoreSetup.Test { @@ -75,10 +76,23 @@ public void Dispose() } } + static readonly object s_lock = new object(); + private TestProject CopyTestProject(TestProject sourceTestProject) { + // This can race with the filesystem. If we're running this code from two threads, fail fast + bool lockTaken = false; + object lockObj = s_lock; + Monitor.TryEnter(lockObj, 0, ref lockTaken); + if (!lockTaken) + { + throw new InvalidOperationException("Lock is held, test should not be executed in parallel"); + } + EnsureDirectoryBuildFiles(TestArtifact.TestArtifactsPath); return sourceTestProject.Copy(); + + // Don't release the lock. There should be only one thread running these tests } private void EnsureDirectoryBuildFiles(string testArtifactDirectory)