[Async-sig] async testing question

Chris Jerdonek chris.jerdonek at gmail.com
Sat Jul 1 17:00:57 EDT 2017


On Sat, Jul 1, 2017 at 1:42 PM, Nathaniel Smith <njs at pobox.com> wrote:
> On Jul 1, 2017 3:11 AM, "Chris Jerdonek" <chris.jerdonek at gmail.com> wrote:
> Is there a way to write a test case to check that task.cancel() would
> behave correctly if, say, do_things() is waiting at the line
> do_more()?
>
> One possibility for handling this case with a minimum of mocking would be to
> hook do_more so that it calls task.cancel and then calls the regular
> do_more.
>
> Beyond that it depends on what the actual functions are, I guess. If do_more
> naturally blocks under some conditions then you might be able to set up
> those conditions and then call cancel. Or you could try experimenting with
> tests that call sleep(0) a fixed number of times before issuing the cancel,
> and repeat with different iteration counts to find different cancel points.

Thanks, Nathaniel. The following would be overkill in my case, but
your suggestion makes me wonder if it would make sense for there to be
testing tools that have functions to do things like "run the event
loop until <this future> is at <this line of code>." Do such things
exist? This is a little bit related to what Dima was saying about
tools.

--Chris


More information about the Async-sig mailing list