-
Notifications
You must be signed in to change notification settings - Fork 201
Set TCP_NODELAY on pydevd client connections #2066
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| from unittest import mock | ||
|
|
||
| import pytest | ||
|
|
||
| from _pydevd_bundle import pydevd_comm | ||
|
|
||
|
|
||
| def start_client(monkeypatch, sock): | ||
| monkeypatch.setattr(pydevd_comm, "socket", mock.Mock(return_value=sock)) | ||
| monkeypatch.setattr( | ||
| pydevd_comm.socket_module, | ||
| "getaddrinfo", | ||
| lambda *_: [(pydevd_comm.AF_INET, pydevd_comm.SOCK_STREAM, 0, "", ("127.0.0.1", 5678))], | ||
| ) | ||
| assert pydevd_comm.start_client("localhost", 5678) is sock | ||
| sock.connect.assert_called_once_with(("localhost", 5678)) | ||
|
|
||
|
|
||
| def test_start_client_sets_tcp_nodelay(monkeypatch): | ||
| sock = mock.Mock() | ||
| monkeypatch.setattr(pydevd_comm.socket_module, "TCP_NODELAY", mock.sentinel.tcp_nodelay) | ||
|
|
||
| start_client(monkeypatch, sock) | ||
| sock.setsockopt.assert_any_call(pydevd_comm.socket_module.IPPROTO_TCP, mock.sentinel.tcp_nodelay, 1) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("error", [AttributeError, OSError]) | ||
| def test_start_client_ignores_tcp_nodelay_error(monkeypatch, error): | ||
| sock = mock.Mock() | ||
| sock.setsockopt.side_effect = error | ||
|
|
||
| start_client(monkeypatch, sock) | ||
| sock.setsockopt.assert_any_call(pydevd_comm.socket_module.IPPROTO_TCP, pydevd_comm.socket_module.TCP_NODELAY, 1) | ||
|
|
||
|
|
||
| def test_start_server_sets_tcp_nodelay(monkeypatch): | ||
| server, accepted = mock.Mock(), mock.Mock() | ||
| address = ("127.0.0.1", 5678) | ||
| server.configure_mock(**{"accept.return_value": (accepted, address), "getsockname.return_value": address}) | ||
| monkeypatch.setattr(pydevd_comm, "create_server_socket", mock.Mock(return_value=server)) | ||
| assert pydevd_comm.start_server(0) is accepted | ||
| accepted.setsockopt.assert_called_once_with(pydevd_comm.socket_module.IPPROTO_TCP, pydevd_comm.socket_module.TCP_NODELAY, 1) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On platforms without
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 6c3f75f. The client and server tests now inject a TCP_NODELAY sentinel instead of dereferencing the platform constant, and the server path covers both AttributeError and OSError from setsockopt. Validation: all 6 focused tests passed; Ruff check/format and git diff --check passed. |
||
Uh oh!
There was an error while loading. Please reload this page.