From 43c12aa09311c4717429a6c8f1d04372ddb0f26d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 18 Feb 2022 21:06:38 +0100 Subject: [PATCH 1/4] Fix singleton --- .../FeatureFlag/FeatureFlag.cs | 2 +- .../FeatureFlag/FeatureFlagTests.cs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs diff --git a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs index ee30098221..1c60ef762b 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs @@ -14,7 +14,7 @@ internal partial class FeatureFlag : IFeatureFlag private const string Prefix = "VSTEST_FEATURE_"; - public static IFeatureFlag Instance => new FeatureFlag(); + public static IFeatureFlag Instance { get; } = new FeatureFlag(); static FeatureFlag() { diff --git a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs new file mode 100644 index 0000000000..88f7346757 --- /dev/null +++ b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.TestPlatform.CoreUtilities.UnitTests.FeatureFlag; + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestPlatform.Utilities; + +[TestClass] +public class FeatureFlagTests +{ + [TestMethod] + public void SingletonWorksAsExpected() + { + Assert.IsTrue(ReferenceEquals(FeatureFlag.Instance, FeatureFlag.Instance)); + } +} From 927a6de6299d28ac98f79c7637f86cf483b66658 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Sun, 20 Feb 2022 11:46:56 +0100 Subject: [PATCH 2/4] Update test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Jareš --- .../FeatureFlag/FeatureFlagTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs index 88f7346757..88499ac22d 100644 --- a/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs +++ b/test/Microsoft.TestPlatform.CoreUtilities.UnitTests/FeatureFlag/FeatureFlagTests.cs @@ -10,7 +10,7 @@ namespace Microsoft.TestPlatform.CoreUtilities.UnitTests.FeatureFlag; public class FeatureFlagTests { [TestMethod] - public void SingletonWorksAsExpected() + public void SingletonAlwaysReturnsTheSameInstance() { Assert.IsTrue(ReferenceEquals(FeatureFlag.Instance, FeatureFlag.Instance)); } From def6d03a707b10455567501c82a9f04134fadfce Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Sun, 20 Feb 2022 11:47:22 +0100 Subject: [PATCH 3/4] Update src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Jareš --- .../FeatureFlag/FeatureFlag.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs index 1c60ef762b..d34a312c9c 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs @@ -14,7 +14,7 @@ internal partial class FeatureFlag : IFeatureFlag private const string Prefix = "VSTEST_FEATURE_"; - public static IFeatureFlag Instance { get; } = new FeatureFlag(); + public static IFeatureFlag Instance { get; } ??= new FeatureFlag(); static FeatureFlag() { From 94aea632960a14b62786dd17c3f975d943110bfe Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Sun, 20 Feb 2022 12:00:51 +0100 Subject: [PATCH 4/4] cleanup --- .../FeatureFlag/FeatureFlag.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs index d34a312c9c..ca258a1600 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/FeatureFlag/FeatureFlag.cs @@ -12,9 +12,9 @@ internal partial class FeatureFlag : IFeatureFlag { private static readonly Dictionary FeatureFlags = new(); - private const string Prefix = "VSTEST_FEATURE_"; + private const string VSTEST_FEATURE = nameof(VSTEST_FEATURE); - public static IFeatureFlag Instance { get; } ??= new FeatureFlag(); + public static IFeatureFlag Instance { get; } = new FeatureFlag(); static FeatureFlag() { @@ -24,12 +24,12 @@ static FeatureFlag() // Added for artifact porst-processing, it enable/disable the post processing. // Added in 17.2-preview 7.0-preview - public static string ARTIFACTS_POSTPROCESSING = Prefix + "ARTIFACTS_POSTPROCESSING"; + public static string ARTIFACTS_POSTPROCESSING = VSTEST_FEATURE + "_" + "ARTIFACTS_POSTPROCESSING"; // Added for artifact porst-processing, it will show old output for dotnet sdk scenario. // It can be useful if we need to restore old UX in case users are parsing the console output. // Added in 17.2-preview 7.0-preview - public static string ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX = Prefix + "ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX"; + public static string ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX = VSTEST_FEATURE + "_" + "ARTIFACTS_POSTPROCESSING_SDK_KEEP_OLD_UX"; // For now we're checking env var. // We could add it also to some section inside the runsettings.