-
Notifications
You must be signed in to change notification settings - Fork 780
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
Theory MemberData to allow awaitable method #1698
Comments
Because you are going to use |
@bradwilson Hi, it's an old/closed issue I know, but I just stumbled on it and wanted to know, if there is any possibility in Thanks in advance for the clarification. Cheers R0b |
@R0boC0p In v3, the change was fairly significant, because it encompasses a few new features. The real change exists in v2: IEnumerable<object[]> GetData(
IAttributeInfo dataAttribute,
IMethodInfo testMethod
); v3: ValueTask<IReadOnlyCollection<ITheoryDataRow>?> GetData(
_IAttributeInfo dataAttribute,
_IMethodInfo testMethod,
DisposalTracker disposalTracker
); I was comfortable make that kind of breaking change across major versions. I obviously can't just change things like this in v2 without breaking everybody, so making this work would involve adding a second interface and second base class, and then updating the discovery logic to look for and support both. We couldn't make the two signatures identical, either, because the target frameworks for v2 don't support Alternatively, they could be done via extensibility. It is the |
@R0boC0p It wasn't as difficult as I thought it would be, because I didn't actually need to override as much as I expected to. I could make it work within the existing API surface area, mostly by "cheating" on the await needed for the data by forcing it off onto a thread pool thread and then blocking the synchronous data discovery system. Sample lives here: https://github.com/xunit/samples.xunit/tree/main/AsyncDataExample There's a lot of copied code in the Let me know if you have any questions. |
@bradwilson Thank you so much for your time and consideration! Taking a look at your code, it indeed is now able to get async member data, but as you already mentioned it is going to block the data discovery system. What I am trying to solve:
I hope I could make sense of myself. Thanks again for your support!! |
I don't necessarily know whether an in-built async data retrieval would be any faster in v3, because we don't generally do data retrieval in parallel. We assume data retrieval done during discovery is effectively instant, and that any long-duration data retrieval will get marked by the user as delayed to execution time so as not to slow down the discovery process. Parallel data discovery would also only help you here if you're doing this database setup process many times (as opposed to once), and even then the parallelism would likely be gated by how parallel the database engine itself is. Merely reading data from existing database tables would obviously be something that could probably parallelize okay, but if you're actually doing data setup where you're manipulating the tables to put them into a consistent state, then parallelization would potentially run afoul where you might be trying to mutate the same table(s) at the same time and end up colliding with yourself. I'd like to ponder on the idea of parallelizing data discovery before committing to it, because I can see there are at least as many potential pitfalls as benefits, and for the vast majority of users who are creating synthetic data (the majority via |
Hello,
I have a typical test case scenario where I need to test each instance in a collection returned by an asynchronous call to my service class, which looks like the following:
To do so, I am writing my test as a Theory with a MemberData using a method to retrieve all occurrences I need to test.
My test looks like the following:
This is working fine, however in my GetDataEntries() static method, I am using
.Result
on my asynchronous service call.Considering this service call can be, resource wise, quite expensive and that I have several other very similar test cases, I think it would be beneficial to allow usage of async/await to avoid blocking calls in my tests, like when my GetDataEntries() method gets called.
Ideally, my code would look like the following:
However, this causes a compile time error as it looks such setup not to be allowed:
Would not it be beneficial to allow usage of awaitable methods in MemberData?
For reference, I have opened a question on StackOverflow about this very same case:
StackOverflow - xUnit Theory with async MemberData
Thanks.
The text was updated successfully, but these errors were encountered: