-
Notifications
You must be signed in to change notification settings - Fork 743
Assert.Ignore breaks when a Task is returned w/o using async/await #3138
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
Comments
Added a fence to display your stacktrace more cleanly |
Can you point us to the tests that were failing to give us a real world example? Test that return a |
We have a set of tests (Acceptance tests) that are executed to ensure there's no regression. Usually those tests are quite sophisticated and would have an Real world examples below that has started failing with 3.11.0: |
@SeanFeldman you are not updating the support branches but you are updating the version of NUnit on the support branches? I would argue that the behavior in the tests you linked to are using undocumented behavior that we fixed. Our documentation isn't very explicit with |
Support branches are updated. Package containing test source code cannot be bumped up. From the linked documentation:
There's absolutely nothing in the documentation that would rule out using |
The highlighting in your citation of the docs is yours and, arguably, changes the meaning of the sentence. To my knowledge, there has never been any intention of allowing a non-async test method to return Task, although it's possible that changes have occured over time. It would be very interesting to try out this code on various versions of the framework. In particular, I'm surprised that the test is not marked as "not runnable" due to the non-async Task return. Is there a reason you want to return a task? NUnit has not been told what to do with the return value, which is one reason why I would expect the signature to be invalid. |
Brevity. From C# perspective returning a |
You're right that NUnit shouldn't care if the method is public async Task ReturnsTask()
{
throw new SomeException();
}
var task = ReturnsTask();
await task; // Can be combined with Task.WhenAll, etc, and only throws when awaited But this is frowned upon, at least in shipping code: public Task ThrowsBeforeReturningTask()
{
throw new SomeException();
}
var task = ThrowsBeforeReturningTask(); // Throws in an unexpected location
await task; To avoid the async state machine, the proper implementation would be: public Task ReturnsTask()
{
return Task.FromException(new SomeException());
} Indeed, it's frowned upon if you indirectly cause an exception (say, ObjectDisposedException) and don't catch and wrap in Now, I think there are good reasons that you shouldn't have to care when writing test code.
Therefore, my view is that this is a regression of an undocumented but useful feature. |
And by the way, The only time I wouldn't use
And I'm not comfortable proposing that everyone should ignore that warning or that everyone should add |
I can see by reading it that #3095 doesn't affect this scenario. I'll try to get a fix through for this first. |
@SeanFeldman If you'd like to try this out before 3.12.0 is released, you can merge this with your nuget.config and look for version <?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NUnit MyGet" value="https://www.myget.org/F/nunit/api/v3/index.json" />
</packageSources>
</configuration> |
@jnm2 I'll give it a try and report back. Thank you. |
Sorry for delay. Going to test it today/tomorrow and let know. |
@jnm2 confirmed. 3.12.x fixes the problem. Thank you 🙂 |
Thanks for the confirmation! |
@jnm2 how far 3.12.x from being finalized? |
We are behind schedule, but I'm not sure if there's any reason not to release soon. @rprouse, what are you thinking here? |
@jnm2 I would like to get the release out this month if possible. I'd ask the @nunit/framework-team to move any outstanding issues or pull requests to the milestone that we should include in the release so that we can track them. |
@rprouse I threw in #3145 because the PR is nearly merged, but nothing is particularly on my radar. The release date also came up at https://gitter.im/nunit/nunit?at=5c8f99679d9cc8114ade435d. |
Hi folks, any news on 3.12 coming out? Thanks. |
@rprouse Can I help? |
@SeanFeldman thanks for prompting, I'll try to get the release out soon. @jnm2 I've gone through the issues in the milestone and cleaned them up. Nearly everything will be resolved once I review your PR #3095 except for #3085. That looks somewhat serious, but do you think it is enough to hold up a release for? Also, is there anything else out there that should be in the release? |
@mikkelbu I agree, that one would be really good to get in now that the WinForms and WPF crowd (myself included) are going to be moving to .NET Core. What happened there, anyway? I totally failed to see the mentions. 🤦♂️ Looks like it's ready to merge, so I'll get it done. |
@rprouse Okay, #3036 and #3085 are both fixed in master. I threw in the issues for #3214 and #3098 because they just need a second review and they look low-risk, but feel free to pull them out if you see something. There's a chance I'll want to get #3205 and #3206 in too, but I haven't opened either one of them yet. It's late and I'll have time tomorrow. |
Uh oh!
There was an error while loading. Please reload this page.
Writing a test that invokes
Assert.Ignore()
and it fails with the following exception:Stacktrace
The failing test looks as the following:
Changing the test to include the
async
keyword withawait
fixes this test:This fails with NUnit 3.11.0, but works with earlier versions.
Tested with .NET Framework 4.5.2
The text was updated successfully, but these errors were encountered: