From bd24d1a6d42b6bc1d6a16c2973bab2eecc05d146 Mon Sep 17 00:00:00 2001 From: Josue Nina Date: Mon, 15 Jun 2026 12:44:29 -0500 Subject: [PATCH] Fix race condition in Isolator cancellation test --- Tests/Common/IsolatorTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Tests/Common/IsolatorTests.cs b/Tests/Common/IsolatorTests.cs index 6eaf5a3b7319..fad304c51922 100644 --- a/Tests/Common/IsolatorTests.cs +++ b/Tests/Common/IsolatorTests.cs @@ -53,13 +53,14 @@ public void Cancellation() var ended = false; var canceled = false; var result = false; - isolator.CancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100)); try { result = isolator.ExecuteWithTimeLimit( TimeSpan.FromSeconds(5), () => { executed = true; + // cancel only once the code block is running so the task can't be canceled before it starts + isolator.CancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100)); Thread.Sleep(5000); ended = true; },