From 4283f08ea32bfc5f2f632fa3f14f31797c0617eb Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Thu, 2 Apr 2026 16:42:46 -0500 Subject: [PATCH] Use Interlocked.Increment for thread-safe test counters With [assembly: Parallelize(Scope = ExecutionScope.MethodLevel)], ConsumeAsync may be called concurrently from multiple threads. Passed++/Failed++/Skipped++ are not atomic and can lose increments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- TestInstrumentation.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/TestInstrumentation.cs b/TestInstrumentation.cs index 4f29acc..adda099 100644 --- a/TestInstrumentation.cs +++ b/TestInstrumentation.cs @@ -59,7 +59,10 @@ public override void OnStart() class ResultConsumer(Instrumentation instrumentation) : IDataConsumer { - public int Passed, Failed, Skipped; + int _passed, _failed, _skipped; + public int Passed => _passed; + public int Failed => _failed; + public int Skipped => _skipped; public string? TrxReportPath; public string Uid => nameof(ResultConsumer); @@ -90,7 +93,7 @@ FailedTestNodeStateProperty or ErrorTestNodeStateProperty if (outcome is null) return Task.CompletedTask; - _ = outcome switch { "passed" => Passed++, "failed" => Failed++, _ => Skipped++ }; + _ = outcome switch { "passed" => Interlocked.Increment(ref _passed), "failed" => Interlocked.Increment(ref _failed), _ => Interlocked.Increment(ref _skipped) }; var id = node.Properties.SingleOrDefault(); var b = new Bundle();