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
Assertion that asynchronous operation completes within time span #1001
Comments
I have come across this problem too. Sometimes those asynchronous operations that are being tested may never complete or may take an unusual long time to complete. As a result, the whole test run takes forever to complete. Sometimes I just want a test to fail if the asynchronous operation does not complete within a given amount of time. In most cases, there actually is something wrong if a task takes forever to complete. I would love to see assertions that help me to express the following:
|
One more thing: What should happen to those tasks that did not complete in case the assertions failed? Is it a problem if tasks stay alive after the test is done? If there is a |
So, @bitbonk, you prefer following the Invoking pattern? Regarding the |
The |
@dennisdoomen, which approach you prefer? Based on Invoking or directly on the Task? |
Both ;-) |
äähhmmm, oooh... |
I would prefer handling with the Task directly because: |
Hi @dennisdoomen and @jnyrup, you remember my attempt to contribute this extension? Today we have simlar extension with the Invoking feature. Fine, so far. We like the very short version I mentioned initially: this.myServer.OpenAsync().Should().CompleteWithin(100.MilliSeconds()); You did not want to introduce this because it is an overlay of the
So, I can identify only a single method which can be used used reasonable on Tasks in the current API. This one can be added to be compatible. Further you mentioned the timing may be inaccurate because the task is already running when check timer is started. What do you think today? Additional questions to discuss? |
If I recall correctly, the main problem was the discussion around |
|
The timing accuracy is a minor problem of assertion directly on myTask.Should().NotThrow(); While we could leave the exception testing assertions out of the API for |
If we support it, we would have to do it in a consistent way. So every assertion that you can run on a |
To be honest I don't really see a problem if the assertions available on More importantly: Similar differences already exist elsewhere. For example I can't just do If we would do the same thing for tasks (having to wrap it into a |
I think, discussion is completed so far. |
Testing asynchronous operations is currently available like this:
I'm missing the option just check, that the operation will complete (and not throw) within specific time range. Therefore a new assertion could be created:
Such an idea I already mentioned in #990.
While thinking about the implementation I found a different approach.
Why to I need the indirection using "Invoking"? Why not asserting the Task directly:
The text was updated successfully, but these errors were encountered: