txaws icon indicating copy to clipboard operation
txaws copied to clipboard

txaws.s3.tests.test_client.LiveS3TestCase.test_objects can fail with DirtyReactorAggregateError

Open exarkun opened this issue 8 years ago • 1 comments

On a local test run:

[ERROR]
Traceback (most recent call last):
Failure: twisted.trial.util.DirtyReactorAggregateError: Reactor was unclean.
Selectables:
<<class 'twisted.internet.tcp.Client'> to ('s3.amazonaws.com', 443) at 7fd3e54bb550>

txaws.s3.tests.test_client.LiveS3TestCase.test_objects

This came from the improved-s3-put_object-testing branch which may be relevant but my hunch is that it's caused by a race condition between disconnection and the last Deferred in the test and happens randomly, even on master, with some frequency.

exarkun avatar Jan 09 '17 15:01 exarkun

The deferred returned by Agent.request will fire immediately when the request completes, whereas the underlying connection may still be busy with TCP/TLS shutdown, or idle in a connection pool. The way I've usually solved this is to create a connection pool explicitly in my tests, then you can invoke https://twistedmatrix.com/documents/current/api/twisted.web.client.HTTPConnectionPool.html#closeCachedConnections at the end of the test to wait for the connection(s) to be closed.

mithrandi avatar Jan 10 '17 00:01 mithrandi