-
Notifications
You must be signed in to change notification settings - Fork 742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ThrowsAsync reports OperationCanceledException as TaskCanceledException #2168
Comments
NUnit waits for the Task by calling its Wait() method and it is that method that discards your OperationCanceledException and instead throws an AggreateException with an inner TaskCanceledException. [Test]
public void OperationCanceledExceptionIsReplacedByTaskCanceledException()
{
Assert.That(() => Foo().Wait(),
Throws.TypeOf<AggregateException>().With.InnerException.TypeOf<TaskCanceledException>());
}
private static async Task Foo()
{
await Task.Yield();
throw new OperationCanceledException();
} Not sure NUnit can do anything about that. |
I'd much rather NUnit called |
@jnm2 Feel free to assign this to yourself. I'm thinking it may not be quite so simple, but let's see. |
That's because TaskCanceledException derives from OperationCanceledException; the equivalent test would actually be |
@CharliePoole Implementing this fix will be half a step away from supporting all C# awaitable types. Since C# now supports arbitrary task-like return types on async methods, such as |
Oh, btw. The net40 async polyfill will exhibit the same bad behavior with If you target net45+ or netstandard, you're fine. |
I'm having the same issue. Also, the MSTest framework doesn't have this problem. |
Eh... the @nunit/framework-team is waiting on me for this. The work is basically done, but I haven't written all the tests I want us to carry forward. I would like comments on #2181. |
Fixed in the prerelease feed and included in 3.12 which is just around the corner! |
The
ThrowsAsync
method reports exceptions of typeOperationCanceledException
asTaskCanceledException
instead.Repro:
Result:
Other exception types are reported correctly. The following test passes.
I believe it's possible to workaround this issue using the "constraint model". The following test passes.
I observed the issue in version 3.5.0. I updated to 3.6.1 and confirmed that the issue is still present in the latest version.
I also installed the console runner and tested from the command line as per the contributing guidelines. Test output below.
The text was updated successfully, but these errors were encountered: