Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ def start_client(host, port):
s.setsockopt(socket_module.IPPROTO_TCP, socket_module.TCP_KEEPCNT, 5)
except (AttributeError, OSError):
pass # May not be available everywhere.
try:
s.setsockopt(socket_module.IPPROTO_TCP, socket_module.TCP_NODELAY, 1)
except (AttributeError, OSError):
pass # May not be available everywhere.

try:
# 10 seconds default timeout
Expand Down
43 changes: 43 additions & 0 deletions src/debugpy/_vendored/pydevd/tests_python/test_pydevd_comm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from unittest import mock

from _pydevd_bundle import pydevd_comm


def start_client(monkeypatch, sock):
monkeypatch.setattr(pydevd_comm, "socket", lambda *_: sock)
monkeypatch.setattr(pydevd_comm.socket_module, "getaddrinfo", lambda *_: [])
return pydevd_comm.start_client("localhost", 5678)
Comment thread
nightcityblade marked this conversation as resolved.
Outdated


def test_start_client_sets_tcp_nodelay(monkeypatch):
sock = mock.Mock()
tcp_nodelay = mock.sentinel.tcp_nodelay
monkeypatch.setattr(pydevd_comm.socket_module, "TCP_NODELAY", tcp_nodelay)

assert start_client(monkeypatch, sock) is sock
sock.setsockopt.assert_any_call(
pydevd_comm.socket_module.IPPROTO_TCP,
tcp_nodelay,
1,
Comment thread
nightcityblade marked this conversation as resolved.
Outdated
)


def test_start_client_without_tcp_nodelay(monkeypatch):
sock = mock.Mock()
monkeypatch.delattr(pydevd_comm.socket_module, "TCP_NODELAY", raising=False)

assert start_client(monkeypatch, sock) is sock


def test_start_client_ignores_tcp_nodelay_error(monkeypatch):
sock = mock.Mock()
tcp_nodelay = mock.sentinel.tcp_nodelay
monkeypatch.setattr(pydevd_comm.socket_module, "TCP_NODELAY", tcp_nodelay)

def set_option(_level, option, _value):
if option is tcp_nodelay:
raise OSError

sock.setsockopt.side_effect = set_option

assert start_client(monkeypatch, sock) is sock
Loading