Skip to content

Commit 6ba9bb9

Browse files
test(audience-http): accept HttpClient's TaskCanceledException wrap
SendBatchAsync_CallerCancelled_Throws was asserting the exact type `OperationCanceledException` via `Assert.ThrowsAsync`. HttpClient internally catches the OCE our mock throws and rethrows it as `TaskCanceledException` (a subclass), so `ThrowsAsync` — which is exact-type — missed. Switch to `CatchAsync<OperationCanceledException>`, which accepts the whole cancellation family. This is what we actually want to assert: "cancellation propagated", not "HttpClient happens to throw this exact subclass". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 81ff2e9 commit 6ba9bb9

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/Packages/Audience/Tests/Runtime/Transport/HttpTransportTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,10 @@ public void SendBatchAsync_CallerCancelled_Throws_DoesNotDeleteOrRecordFailure()
415415
using var cts = new CancellationTokenSource();
416416
cts.Cancel();
417417

418-
Assert.ThrowsAsync<OperationCanceledException>(
418+
// CatchAsync (not ThrowsAsync) because HttpClient re-wraps our mock's
419+
// OperationCanceledException as TaskCanceledException before rethrowing.
420+
// We want to assert the cancellation *family*, not a specific subclass.
421+
Assert.CatchAsync<OperationCanceledException>(
419422
async () => await transport.SendBatchAsync(cts.Token));
420423

421424
Assert.AreEqual(1, _store.Count(), "cancelled send must not delete the batch");

0 commit comments

Comments
 (0)