mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-07 19:04:21 +00:00
Cancel timeout on failures too.
This commit is contained in:
parent
6c3e9e670d
commit
2ab8e3e8d2
@ -169,7 +169,12 @@ def limited_content(
|
||||
collector.f.seek(0)
|
||||
return collector.f
|
||||
|
||||
return d.addCallback(done)
|
||||
def failed(f):
|
||||
if timeout.active():
|
||||
timeout.cancel()
|
||||
return f
|
||||
|
||||
return d.addCallbacks(done, failed)
|
||||
|
||||
|
||||
def _decode_cbor(response, schema: Schema, clock: IReactorTime):
|
||||
|
@ -280,6 +280,14 @@ class TestApp(object):
|
||||
self.clock.callLater(59 + 59, request.write, b"c")
|
||||
return Deferred()
|
||||
|
||||
@_authorized_route(_app, set(), "/die_unfinished", methods=["GET"])
|
||||
def die(self, request, authorization):
|
||||
"""
|
||||
Dies half-way.
|
||||
"""
|
||||
request.transport.loseConnection()
|
||||
return Deferred()
|
||||
|
||||
|
||||
def result_of(d):
|
||||
"""
|
||||
@ -423,6 +431,22 @@ class CustomHTTPServerTests(SyncTestCase):
|
||||
with self.assertRaises(CancelledError):
|
||||
error[0].raiseException()
|
||||
|
||||
def test_limited_content_cancels_timeout_on_failed_response(self):
|
||||
"""
|
||||
If the response fails somehow, the timeout is still cancelled.
|
||||
"""
|
||||
response = result_of(
|
||||
self.client.request(
|
||||
"GET",
|
||||
"http://127.0.0.1/die",
|
||||
)
|
||||
)
|
||||
|
||||
d = limited_content(response, self._http_server.clock, 4)
|
||||
with self.assertRaises(ValueError):
|
||||
result_of(d)
|
||||
self.assertEqual(len(self._http_server.clock.getDelayedCalls()), 0)
|
||||
|
||||
|
||||
class HttpTestFixture(Fixture):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user