You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Manual: System.OperationCanceledException
ShoudlyV1: System.Threading.Tasks.TaskCanceledException
Variant 2 did not got Exception
Variant 2 did not got TaskCanceledException
Variant 2 did not got OperationCanceledException
I've expected that It will be OperationCanceledException in all variants. It seems, that ThrowAsync still works wrong in case of canceled task.
I want to add the following example, which overlaps with @alexnnenn's example:
OperationCanceledException is not sealed. This allows TaskCanceledException to extend it but also offers an open-ended mechanism for attaching custom information to the transition of a Task's state from running to canceled.
Imagine you want to await the running of a System.Diagnostics.Process and limit this await with a CancellationToken. It can prove useful to extend OperationCanceledException and avoid replacing the Task.IsCanceled experience but rather augment it with, say, the stdout and stderr that had successfully been captured thus far:
publicasync Task Run_ShouldThrowWCE(){usingCancellationTokenSourcects=new(TimeSpan.FromMilliseconds(1));varact=()=> sut.Run("foo","bar", cts.Token);
act.ShouldThrowAsync<WaitCanceledException>();// 💥 will throw, causing the test to fail, which is surprising, at least for me}
I don't know any straightforward way to access the underlying exception of a canceled task.
Nevertheless, the solution chosen here is not particularly friendly to niche use cases, where the user wants to distinguish between OperationCanceledException, TaskCanceledException, etc.:
I've just tried testing call of function Foo and got different behaviour in test, depending on what variant I use:
The output is:
I've expected that It will be OperationCanceledException in all variants. It seems, that ThrowAsync still works wrong in case of canceled task.
I've used latest available release version 4.0.3.
Originally posted by @alexnnenn in #560 (comment)
The text was updated successfully, but these errors were encountered: