From 491eedf77edfecd24c6c093e2c11b2768eef0f0c Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Thu, 5 Mar 2026 23:39:44 +0100 Subject: [PATCH] Enable parallel test execution, mark timing-sensitive test as non-parallel, and use Interlocked for TaskId --- YesNt.Interpreter.Tests/AssemblyInfo.cs | 3 +++ YesNt.Interpreter.Tests/ConsoleStatementsTests.cs | 1 + YesNt.Interpreter/Runtime/RuntimeInformation.cs | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 YesNt.Interpreter.Tests/AssemblyInfo.cs diff --git a/YesNt.Interpreter.Tests/AssemblyInfo.cs b/YesNt.Interpreter.Tests/AssemblyInfo.cs new file mode 100644 index 0000000..38707ae --- /dev/null +++ b/YesNt.Interpreter.Tests/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.MethodLevel)] diff --git a/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs b/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs index 61ddae7..1ba7cbc 100644 --- a/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs +++ b/YesNt.Interpreter.Tests/ConsoleStatementsTests.cs @@ -76,6 +76,7 @@ public class ConsoleStatementsTests } [TestMethod] + [DoNotParallelize] // timing-sensitive: relies on Thread.Sleep to let the interpreter reach %read_key public void ReadKeyCanBeInterruptedByStopTest() { YesNtInterpreter interpreter = new YesNtInterpreter(); diff --git a/YesNt.Interpreter/Runtime/RuntimeInformation.cs b/YesNt.Interpreter/Runtime/RuntimeInformation.cs index 862735a..371ed94 100644 --- a/YesNt.Interpreter/Runtime/RuntimeInformation.cs +++ b/YesNt.Interpreter/Runtime/RuntimeInformation.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using YesNt.Interpreter.Utilities; @@ -191,7 +192,7 @@ internal sealed class RuntimeInformation IsLocalSearch = false; LineNumber = 0; #pragma warning disable S2696 // internalTaskId is a shared counter intentionally incremented by each Reset call - TaskId = ++internalTaskId; + TaskId = Interlocked.Increment(ref internalTaskId); #pragma warning restore S2696 }