Fix TaskCanceledException in TestReporter when ConnectedTask is canceled#1544
Conversation
When _listener.ConnectedTask is canceled (e.g. due to process timeout), Task.IsCompleted returns true but accessing .Result throws TaskCanceledException. This caused numerous test runs to report as HarnessException instead of reporting their actual result. Use IsCompletedSuccessfully instead of IsCompleted to guard .Result access - it only returns true for tasks that ran to completion (not canceled or faulted). Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes a cancellation edge-case in the iOS shared TestReporter so canceled listener connection tasks don’t throw TaskCanceledException when their Result is accessed, allowing test runs to report the actual outcome instead of failing as a harness error.
Changes:
- Switches guards from
Task.IsCompletedtoTask.IsCompletedSuccessfullybefore reading_listener.ConnectedTask.Result. - Applies the same fix both for the “test execution started” check and for the empty run-log launch-failure detection.
vitek-karas
left a comment
There was a problem hiding this comment.
If it's easy we should add a test, other than that this looks good.
|
@copilot Add unit test covering the scenario this change fixes: when ConnectedTask is canceled and the run log is empty, CollectSimulatorResult should not throw and should treat it as a launch failure |
Co-authored-by: Copilot <[email protected]>
|
I replaced copilot locally (same prompt :-)) - unfortunately CCA doesn't work on PRs from forks... |
|
/ba-g dotnet/runtime#123796 |
When _listener.ConnectedTask is canceled (e.g. due to process timeout),
Task.IsCompleted returns true but accessing .Result throws
TaskCanceledException. This caused numerous test runs to report as
HarnessException instead of reporting their actual result.
Use IsCompletedSuccessfully instead of IsCompleted to guard .Result
access - it only returns true for tasks that ran to completion (not
canceled or faulted).