From 7ff49d96fe84dbc80e24f57c4ced1f626a9a3cf3 Mon Sep 17 00:00:00 2001 From: tmat Date: Sat, 16 Nov 2024 07:44:58 -0800 Subject: [PATCH 1/3] Apply xunit configuration to all tests for better test failure diagnostics --- test/Directory.Build.props | 3 +++ test/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj | 1 - test/dotnet-new.Tests/xunit.runner.json | 5 ----- test/dotnet-watch.Tests/dotnet-watch.Tests.csproj | 3 --- test/dotnet.Tests/dotnet.Tests.csproj | 4 ---- test/dotnet.Tests/xunit.runner.json | 6 ------ test/{dotnet-watch.Tests => }/xunit.runner.json | 0 7 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 test/dotnet-new.Tests/xunit.runner.json delete mode 100644 test/dotnet.Tests/xunit.runner.json rename test/{dotnet-watch.Tests => }/xunit.runner.json (100%) diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 82e7362363f8..4840ad756143 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -38,4 +38,7 @@ + + + diff --git a/test/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj b/test/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj index ebbe79272df2..9fe5414c384d 100644 --- a/test/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj +++ b/test/dotnet-new.Tests/dotnet-new.IntegrationTests.csproj @@ -76,7 +76,6 @@ namespace Microsoft.DotNet.Cli.New.IntegrationTests - diff --git a/test/dotnet-new.Tests/xunit.runner.json b/test/dotnet-new.Tests/xunit.runner.json deleted file mode 100644 index 4dca131cc476..000000000000 --- a/test/dotnet-new.Tests/xunit.runner.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", - "diagnosticMessages": true, - "longRunningTestSeconds": 120 -} diff --git a/test/dotnet-watch.Tests/dotnet-watch.Tests.csproj b/test/dotnet-watch.Tests/dotnet-watch.Tests.csproj index bf367142bbc3..774159200782 100644 --- a/test/dotnet-watch.Tests/dotnet-watch.Tests.csproj +++ b/test/dotnet-watch.Tests/dotnet-watch.Tests.csproj @@ -9,9 +9,6 @@ - - - diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index 76d95d0b1c39..4bb8bfdc1df5 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -125,10 +125,6 @@ - - - - diff --git a/test/dotnet.Tests/xunit.runner.json b/test/dotnet.Tests/xunit.runner.json deleted file mode 100644 index d766d6750a82..000000000000 --- a/test/dotnet.Tests/xunit.runner.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", - "diagnosticMessages": true, - "internalDiagnosticMessages": true, - "longRunningTestSeconds": 120 -} diff --git a/test/dotnet-watch.Tests/xunit.runner.json b/test/xunit.runner.json similarity index 100% rename from test/dotnet-watch.Tests/xunit.runner.json rename to test/xunit.runner.json From 884e5f043e2eacef777cb27cd8c50cdff16dbff0 Mon Sep 17 00:00:00 2001 From: tmat Date: Sat, 16 Nov 2024 14:19:54 -0800 Subject: [PATCH 2/3] Fix --- test/Directory.Build.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 4840ad756143..e7d9b9edccf3 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -39,6 +39,6 @@ - + From 436a50403447f13a657b8c70ad92a8c1dd2ba0b5 Mon Sep 17 00:00:00 2001 From: Jacques Eloff Date: Tue, 19 Nov 2024 11:31:16 -0800 Subject: [PATCH 3/3] Work around concurrency issue in COM API --- .../list/VisualStudioWorkloads.cs | 60 +++++++++++-------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/Cli/dotnet/commands/dotnet-workload/list/VisualStudioWorkloads.cs b/src/Cli/dotnet/commands/dotnet-workload/list/VisualStudioWorkloads.cs index 43553bb769e9..914211211429 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/list/VisualStudioWorkloads.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/list/VisualStudioWorkloads.cs @@ -19,6 +19,8 @@ namespace Microsoft.DotNet.Workloads.Workload #endif internal static class VisualStudioWorkloads { + private static readonly object s_guard = new(); + private const int REGDB_E_CLASSNOTREG = unchecked((int)0x80040154); /// @@ -204,44 +206,50 @@ internal static IEnumerable WriteSDKInstallRecordsForVSWorkloads(IIn /// A list of Visual Studio instances. private static List GetVisualStudioInstances() { - List vsInstances = new(); - - try + // The underlying COM API has a bug where-by it's not safe for concurrent calls. Until their + // bug fix is rolled out use a lock to ensure we don't concurrently access this API. + // https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2241752/ + lock (s_guard) { - SetupConfiguration setupConfiguration = new(); - ISetupConfiguration2 setupConfiguration2 = setupConfiguration; - IEnumSetupInstances setupInstances = setupConfiguration2.EnumInstances(); - ISetupInstance[] instances = new ISetupInstance[1]; - int fetched = 0; + List vsInstances = new(); - do + try { - setupInstances.Next(1, instances, out fetched); + SetupConfiguration setupConfiguration = new(); + ISetupConfiguration2 setupConfiguration2 = setupConfiguration; + IEnumSetupInstances setupInstances = setupConfiguration2.EnumInstances(); + ISetupInstance[] instances = new ISetupInstance[1]; + int fetched = 0; - if (fetched > 0) + do { - ISetupInstance2 instance = (ISetupInstance2)instances[0]; + setupInstances.Next(1, instances, out fetched); - // .NET Workloads only shipped in 17.0 and later and we should only look at IDE based SKUs - // such as community, professional, and enterprise. - if (Version.TryParse(instance.GetInstallationVersion(), out Version version) && - version.Major >= 17 && - s_visualStudioProducts.Contains(instance.GetProduct().GetId())) + if (fetched > 0) { - vsInstances.Add(instances[0]); + ISetupInstance2 instance = (ISetupInstance2)instances[0]; + + // .NET Workloads only shipped in 17.0 and later and we should only look at IDE based SKUs + // such as community, professional, and enterprise. + if (Version.TryParse(instance.GetInstallationVersion(), out Version version) && + version.Major >= 17 && + s_visualStudioProducts.Contains(instance.GetProduct().GetId())) + { + vsInstances.Add(instances[0]); + } } } + while (fetched > 0); + + } + catch (COMException e) when (e.ErrorCode == REGDB_E_CLASSNOTREG) + { + // Query API not registered, good indication there are no VS installations of 15.0 or later. + // Other exceptions are passed through since that likely points to a real error. } - while (fetched > 0); + return vsInstances; } - catch (COMException e) when (e.ErrorCode == REGDB_E_CLASSNOTREG) - { - // Query API not registered, good indication there are no VS installations of 15.0 or later. - // Other exceptions are passed through since that likely points to a real error. - } - - return vsInstances; } } }