-
Notifications
You must be signed in to change notification settings - Fork 590
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
Stateful async POC #1371
Stateful async POC #1371
Conversation
btw @njsmith you may be interested by this ;-) |
This looks neat, @touilleMan! I haven't had a chance to go through it in detail, but I'm in principle keen. Could you maybe flesh out some documentation/use cases on it? I'm almost completely unfamiliar with Trio and the Python async world, which makes it hard for me to evaluate beyond the nitpicky details of the code. Also, would you like to join the maintainers team? It comes with very little in terms of powers (you get to approve code reviews if you want) or responsibilities (honestly you can keep doing exactly what you're doing), but you get a badge next to your name saying "maintainer" for it. :-) |
Welcome - if you would like to join - to the team 😄 I am really, really keen to get something like this working, but I think it's an open question where it should live - and I'm inclined to say that the appropriate place is in pytest-trio, with Hypothesis adding whatever general hooks would make that practical (for Trio, and asyncio, Twisted, curio, etc.). This would probably mean looking at what parts Hypothesis could stabilise to allow easy implementation of a custom Async stateful tests pose some harder problems in general though, because the order of the steps is no longer the only factor in the ordering - we might need a way for Hypothesis to take charge of the scheduler. In Trio's case this is actually OK as it's mostly-fair and we already seize the global PRNG so the random portion is reproducible. However, adversarial scheduling of coroutines and fault injection (timeouts, cancellations, mock network issues, etc.) would be very powerful for testing - as well as demanding library- and domain-specific implementation and user-facing controls. TLDR; I don't think Hypothesis should provide generic async stateful support, instead we should make it as easy as possible for pytest-trio and similar tools to provide stateful testing customised for their users. Also keen to keep talking this over, but maybe we should move to an issue? |
Sure ! It would be my pleasure ;-)
I will add some documentation. For the usecase you can have a look at this test which implement a simple consumer/producer pattern.
Yup totally agree, all trio-related code has obviously nothing to do with hypothesis (btw @njsmith where do you think the hypothesis-trio compatibility stuff should be put in ? I think the simpler way would be to put it into pytest-trio, but on the other hand this is not pytest-related stuff strictly speaking...)
This seems like the right thing to do, but I guess it's something totally dependent of the async framework so I can't see a way to do this in a generic way from hypothesis. I would be more willing of providing a big empty hole for the framework to run and let it responsible for everything.
Agree |
OK - on the Hypothesis end, I've added a comment to #1300 outlining our aim to support other stateful-like tests downstream. This isn't really the right place to discuss the Trio end, but Hypothesis also recommends that extensions have names like I'll close this pull request because it's unlikely to be merged, but I'm excited to keep working on both ends of 'fuzz Trio programs with Hypothesis' problem and look forward to seeing where we go next. |
This is a simple proof of concept implementing async support to stateful testing.
The main idea is to allow
GenericStateMachine
sub-classes to define a_custom_runner
method thatStateMachineRunner
will call when a run need to be done.This allow different framework to implement they own custom runner (just like what has been done with #1343). For instance trio's
_custom_runner
create a nursery and allow step rules to access it through a specialget_root_nursery
method.This is currently super rough stuff, so feedback greatly wanted ;-)