From 9c4dc66cd269455d82293b67671c857e0db0a363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 13 Dec 2024 17:20:43 +0100 Subject: [PATCH 1/4] Avoid more overhead of assembly initialize --- eng/Versions.props | 2 +- .../MSTest.TestAdapter/Execution/UnitTestRunner.cs | 13 ++++++++++--- .../Services/ExecutionContextService.cs | 9 ++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index d7804ec652..6cb4df1ed9 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,7 +1,7 @@ - 3.8.0 + 3.9.0 1.6.0 preview diff --git a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs index 6d6e854add..2364ddaabc 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs @@ -160,15 +160,22 @@ internal UnitTestResult[] RunSingleTest(TestMethod testMethod, IDictionary private static void SaveExecutionContext(IExecutionContextScope executionContextScope) { + int a = 1; + if (a == 1) + { + return; + } + var capturedContext = ExecutionContext.Capture(); switch (executionContextScope) { From 756c33d6b7fc930d5e50584762e5b835c3e7c3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 13 Dec 2024 17:24:22 +0100 Subject: [PATCH 2/4] revert --- eng/Versions.props | 2 +- .../Services/ExecutionContextService.cs | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 6cb4df1ed9..d7804ec652 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,7 +1,7 @@ - 3.9.0 + 3.8.0 1.6.0 preview diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/ExecutionContextService.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/ExecutionContextService.cs index bdd20dfaf5..c38800d1c0 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/ExecutionContextService.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/ExecutionContextService.cs @@ -55,8 +55,7 @@ internal static void RunActionOnContext(Action action, IExecutionContextScope ex // TODO: Log (trace/debug) the execution context scope and the current execution context. // This would be particularly useful if we have a strange context issue to understand what is being set or not, // What we manage to capture and what we don't, etc. - int a = 1; - if (a == 1 || GetScopedExecutionContext(executionContextScope) is not { } executionContext) + if (GetScopedExecutionContext(executionContextScope) is not { } executionContext) { // We don't have any execution context (that's usually the case when it is being suppressed), so we can run the action directly. action(); @@ -89,12 +88,6 @@ internal static void RunActionOnContext(Action action, IExecutionContextScope ex /// private static void SaveExecutionContext(IExecutionContextScope executionContextScope) { - int a = 1; - if (a == 1) - { - return; - } - var capturedContext = ExecutionContext.Capture(); switch (executionContextScope) { From f9e5307f2154a3966142f7684ca516405964a05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Fri, 13 Dec 2024 17:26:23 +0100 Subject: [PATCH 3/4] Style --- src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs index 2364ddaabc..0e7b634464 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs @@ -173,9 +173,12 @@ internal UnitTestResult[] RunSingleTest(TestMethod testMethod, IDictionary Date: Fri, 13 Dec 2024 17:41:56 +0100 Subject: [PATCH 4/4] and class --- src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs b/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs index fe29c5998e..77023f6088 100644 --- a/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs +++ b/src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs @@ -346,6 +346,11 @@ public void RunClassInitialize(TestContext testContext) internal UnitTestResult GetResultOrRunClassInitialize(ITestContext testContext, string initializationLogs, string initializationErrorLogs, string initializationTrace, string initializationTestContextMessages) { + if (IsClassInitializeExecuted) + { + return new UnitTestResult(ObjectModelUnitTestOutcome.Passed, null); + } + bool isSTATestClass = AttributeComparer.IsDerived(ClassAttribute); bool isWindowsOS = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); if (isSTATestClass