Re: leakage between tests with trial when code under test uses deferToThread

Chris Withers <[email protected]> Mon, 26 Nov 2018 08:35:12 +0000
Newsgroups gmane.comp.python.twisted
Message-ID <[email protected]>
Forgot to include the list in my reply...

On 23/11/2018 22:27, Chris Withers wrote:
> On 23/11/2018 22:22, Glyph wrote:
>>
>>
>>> On Nov 23, 2018, at 7:58 AM, Chris Withers <[email protected]> wrote:
>>>
>>> Hi All,
>>>
>>> Does trial do anything to clean up stuff that's been passed to 
>>> deferToThread?
>>
>> Nope.  It does its best to clean up stuff that it knows is "in" the 
>> reactor (sockets, timers, and the like), but since threads can kind 
>> of do ~whatever~ there hasn't been support for that.
>
> Actually, looks like there's stuff in trial's Janitor class, but it 
> only kicks in after the suite is finished, and I'm seeing leakage 
> between tests within a suite...
>
>> deferToThread is a bit of a special case and you make a good point 
>> here: there should probably be special support for it in trial.
>
> ...which I plan to add in carly in the meantime: basically block with 
> a timeout on everything in the threadpool finishing it's work.
>
> Speaking of which, I'm happy with how carly is turning out, but would 
> still welcome feedback, particularly on how the tests suites feel:
>
> https://github.com/cjw296/carly/tree/master/tests
>
> Just don't read hook.py unless you like head-bendy code ;-)

Okay, so here's what I came up with 
<https://github.com/cjw296/carly/commit/71a1d2bfd501f5c561712c75253fc23c28c3bba7#diff-3670fb1f3b913f6c1ec584fa64302c2dR17>. 
I'm not a fan of the sleep / busy loop pattern, but twisted makes it 
prettymuch impossible to get hold of the ThreadWorkers queue, so that I 
could block on them in this method. Any ideas on improvements would be 
very welcome!

cheers,

Chris

_______________________________________________
Twisted-Python mailing list
[email protected]
https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python