Skip to content

Commit d00e30d

Browse files
authored
Fix race condition in Isolator cancellation test (#9532)
1 parent 98c59a0 commit d00e30d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

Tests/Common/IsolatorTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@ public void Cancellation()
5353
var ended = false;
5454
var canceled = false;
5555
var result = false;
56-
isolator.CancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100));
5756
try
5857
{
5958
result = isolator.ExecuteWithTimeLimit(
6059
TimeSpan.FromSeconds(5),
6160
() => {
6261
executed = true;
62+
// cancel only once the code block is running so the task can't be canceled before it starts
63+
isolator.CancellationTokenSource.CancelAfter(TimeSpan.FromMilliseconds(100));
6364
Thread.Sleep(5000);
6465
ended = true;
6566
},

0 commit comments

Comments
 (0)