Closed leandroltavares closed 3 years ago
It seems that IsolatedAsyncioTestCase
creates a new event loop for each test case.
async_dns shares the same protocol for all clients, so it runs into trouble when the dispatcher which holds the protocol is created with an event loop and the new client is created with another.
In your case, simply adding a tearDown
method would help:
from async_dns.request.udp import Dispatcher
# ...
def tearDown(self):
Dispatcher.data.clear()
I guess the dispatcher / protocol should not be destroyed after each request internally. So maybe I should add this to async_dns.request.clean
so that you can call request.clean
explicitly when you need a clean initial state.
Looks like the tearDown
works, I agree it would be nice to have this clean up routine in cases like that.
Following on this, when I ran several tests, I face some ResourceWarnings
, looks like the socket was not closed, probably the clean up routine should take care of closing it.
Normally this should not happen because we don't force clear cache this way. Anyway I will close the socket in request.clean
.
In the latest alpha ==2.0.0a3
, you should use request.clean
instead:
from async_dns.request import clean
# ...
def tearDown(self):
clean()
Subsequent calls to
DnsClient
fails . Both tests pass independently, but when I run the whole suite the second one timeouts. The following code was used to reproduce the issue using the latest alpha==2.0.0a2
. Python version is3.9.5
Unclear to me why this happens, but I noticed the
CallbackProtocol
does not implement the methodserror_received
andconnection_lost
exposed at the example on python docs. Can this behaviour be related to UDP socket handling, maybe some disposal routines or anything like that?