kquick / Thespian

Python Actor concurrency library
MIT License
189 stars 24 forks source link

TestProbe implementation #49

Open benpillet opened 4 years ago

benpillet commented 4 years ago

I’ve been looking at how Akka does testing and there’s a TestProbe class to support expected behavior. Is that something that would be useful for thespian? I’m gonna work on an experiment to see if I can write one. Are you interested in a PR for it?

kquick commented 4 years ago

I hadn't been familiar with TestProbe, but it does look like it could be useful for testing based on a quick assessment. I think the main challenge will be determining the best way to provide this functionality in a Python/Thespian configuration, but I'd be happy to see something like this contributed to Thespian.

Do you have a draft of how you think this would look?

benpillet commented 4 years ago

I don’t have a draft yet, but I’m gonna work on it the next week or so. I’m thinking a probe will have 2 main parts, a TestProbeActor and a corresponding TestProbe class outside the actor system. The TestProbe will use ask() to bring the messages out of the actor system to do assertions/expects. I don’t see a way to do the assertions directly on the TestProbeActor without complicating the interface too much. Let me know if I’m missing something around that. I’ll come back with a draft when I have something 👍

kquick commented 4 years ago

Any assertion in an Actor will manifest as an exception: Thespian will re-instate the actor and try delivering the message again, and on the second failure it will re-instate the actor but return the message in a PoisonMessage wrapper to the sender. This may or may not be a useful method of testing for you, but your assertions/expects in the external TestProbe will likely integrate more directly with whatever testing framework you intend to use.

Thanks for the update, and I'm happy to provide more specific feedback when your plans are more concrete.