summary refs log tree commit diff
path: root/tests/http
diff options
context:
space:
mode:
authorPatrick Cloke <clokep@users.noreply.github.com>2021-02-18 09:01:29 -0500
committerGitHub <noreply@github.com>2021-02-18 09:01:29 -0500
commit8ec221710329c157a0c83d401e592a325ae02c20 (patch)
tree18d2d3e555405132ab0a9bee5d2d1cd05e5680d2 /tests/http
parentAdd http2 to the nginx example config (#9390) (diff)
downloadsynapse-8ec221710329c157a0c83d401e592a325ae02c20.tar.xz
Reduce the memory usage of previewing media files. (#9421)
This reduces the memory usage of previewing media files which
end up larger than the `max_spider_size` by avoiding buffering
content internally in treq.

It also checks the `Content-Length` header in additional places
instead of streaming the content to check the body length.
Diffstat (limited to 'tests/http')
-rw-r--r--tests/http/test_client.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/tests/http/test_client.py b/tests/http/test_client.py

index f17c122e93..2d9b733be0 100644 --- a/tests/http/test_client.py +++ b/tests/http/test_client.py
@@ -18,6 +18,7 @@ from mock import Mock from twisted.python.failure import Failure from twisted.web.client import ResponseDone +from twisted.web.iweb import UNKNOWN_LENGTH from synapse.http.client import BodyExceededMaxSize, read_body_with_max_size @@ -27,12 +28,12 @@ from tests.unittest import TestCase class ReadBodyWithMaxSizeTests(TestCase): def setUp(self): """Start reading the body, returns the response, result and proto""" - self.response = Mock() + response = Mock(length=UNKNOWN_LENGTH) self.result = BytesIO() - self.deferred = read_body_with_max_size(self.response, self.result, 6) + self.deferred = read_body_with_max_size(response, self.result, 6) # Fish the protocol out of the response. - self.protocol = self.response.deliverBody.call_args[0][0] + self.protocol = response.deliverBody.call_args[0][0] self.protocol.transport = Mock() def _cleanup_error(self): @@ -88,7 +89,7 @@ class ReadBodyWithMaxSizeTests(TestCase): self.protocol.dataReceived(b"1234567890") self.assertIsInstance(self.deferred.result, Failure) self.assertIsInstance(self.deferred.result.value, BodyExceededMaxSize) - self.protocol.transport.loseConnection.assert_called_once() + self.protocol.transport.abortConnection.assert_called_once() # More data might have come in. self.protocol.dataReceived(b"1234567890")