Skip to content

Commit 0a75d59

Browse files
Copilotilonatommy
andcommitted
Add test for cancellation token taking precedence over timeout
Co-authored-by: ilonatommy <[email protected]>
1 parent 169cab9 commit 0a75d59

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/JSInterop/Microsoft.JSInterop/test/JSRuntimeTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ public async Task InvokeAsync_CancelsAsyncTasksWhenCancellationTokenFires()
8282
await Assert.ThrowsAsync<TaskCanceledException>(async () => await task);
8383
}
8484

85+
[Fact]
86+
public async Task InvokeAsync_CancelsWithTaskCanceledException_WhenCancellationTokenFiresBeforeTimeout()
87+
{
88+
// Arrange
89+
using var cts = new CancellationTokenSource();
90+
var runtime = new TestJSRuntime();
91+
// Set a long timeout, but cancel before it fires
92+
runtime.DefaultTimeout = TimeSpan.FromSeconds(10);
93+
94+
// Act
95+
var task = runtime.InvokeAsync<object>("test identifier 1", cts.Token, new object[] { "arg1", 123, true });
96+
97+
cts.Cancel();
98+
99+
// Assert - Should throw TaskCanceledException, not TimeoutException
100+
await Assert.ThrowsAsync<TaskCanceledException>(async () => await task);
101+
}
102+
85103
[Fact]
86104
public async Task InvokeAsync_DoesNotStartWorkWhenCancellationHasBeenRequested()
87105
{

0 commit comments

Comments
 (0)