Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodelay #680

Merged
merged 11 commits into from
Dec 15, 2015
Prev Previous commit
Next Next commit
Implement tcp_cork on web response level
  • Loading branch information
asvetlov committed Dec 14, 2015
commit d9a9cf236fe0c6ef17f29ce254c0a3b99e0349ca
1 change: 1 addition & 0 deletions aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ def _start(self, request):
not keep_alive,
self._reason)
resp_impl.transport.set_tcp_nodelay(self._tcp_nodelay)
resp_impl.transport.set_tcp_cork(self._tcp_cork)

self._copy_cookies()

Expand Down
43 changes: 43 additions & 0 deletions tests/test_web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ def test_set_tcp_nodelay_on_start():
with mock.patch('aiohttp.web_reqrep.ResponseImpl'):
resp_impl = yield from resp.prepare(req)
resp_impl.transport.set_tcp_nodelay.assert_called_with(True)
resp_impl.transport.set_tcp_cork.assert_called_with(False)


@pytest.mark.run_loop
Expand All @@ -621,6 +622,7 @@ def test_set_tcp_nodelay_after_start():

with mock.patch('aiohttp.web_reqrep.ResponseImpl'):
resp_impl = yield from resp.prepare(req)
resp_impl.transport.set_tcp_cork.assert_called_with(False)
resp_impl.transport.set_tcp_nodelay.assert_called_with(True)
resp.set_tcp_nodelay(False)
assert not resp.tcp_nodelay
Expand All @@ -630,6 +632,47 @@ def test_set_tcp_nodelay_after_start():
resp_impl.transport.set_tcp_nodelay.assert_called_with(True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True ? maybe 1 or 0 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bool is subclass of int



def test_default_cork():
resp = StreamResponse()
assert not resp.tcp_cork


def test_set_tcp_cork_before_start():
resp = StreamResponse()
resp.set_tcp_cork(True)
assert resp.tcp_cork
resp.set_tcp_cork(False)
assert not resp.tcp_cork


@pytest.mark.run_loop
def test_set_tcp_cork_on_start():
req = make_request('GET', '/')
resp = StreamResponse()
resp.set_tcp_cork(True)

with mock.patch('aiohttp.web_reqrep.ResponseImpl'):
resp_impl = yield from resp.prepare(req)
resp_impl.transport.set_tcp_nodelay.assert_called_with(False)
resp_impl.transport.set_tcp_cork.assert_called_with(True)


@pytest.mark.run_loop
def test_set_tcp_cork_after_start():
req = make_request('GET', '/')
resp = StreamResponse()

with mock.patch('aiohttp.web_reqrep.ResponseImpl'):
resp_impl = yield from resp.prepare(req)
resp_impl.transport.set_tcp_cork.assert_called_with(False)
resp.set_tcp_cork(True)
assert resp.tcp_cork
resp_impl.transport.set_tcp_cork.assert_called_with(True)
resp.set_tcp_cork(False)
assert not resp.tcp_cork
resp_impl.transport.set_tcp_cork.assert_called_with(False)


# Response class


Expand Down