Skip to content

Commit c601215

Browse files
committed
fix moar tests and faulty logic
1 parent 55c720f commit c601215

4 files changed

Lines changed: 49 additions & 13 deletions

File tree

sentry_sdk/transport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def make_transport(options):
806806
# We default to using HTTP2 transport if the user also has the required h2
807807
# library installed (through the subclass check). The reason is h2 not being
808808
# available on py3.7 which we still support.
809-
use_http2_transport = options.get("http2", True) and not issubclass(
809+
use_http2_transport = options.get("http2") != False and not issubclass(
810810
Http2Transport, HttpTransport
811811
)
812812

tests/integrations/typer/test_typer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def capture_envelope(self, envelope):
2626
if event is not None:
2727
print(event)
2828
29-
transport.HttpTransport.capture_envelope = capture_envelope
29+
transport.BaseHttpTransport.capture_envelope = capture_envelope
3030
3131
init("http://foobar@localhost/123", integrations=[TyperIntegration()])
3232

tests/test_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,8 @@ def test_proxy(monkeypatch, testcase, http2):
362362
def test_socks_proxy(testcase, http2):
363363
kwargs = {}
364364

365-
if not http2:
366-
kwargs["http2"] = False
365+
if http2:
366+
kwargs["_experiments"] = {"transport_http2": True}
367367

368368
if testcase["arg_http_proxy"] is not None:
369369
kwargs["http_proxy"] = testcase["arg_http_proxy"]
@@ -565,10 +565,10 @@ def test_capture_event_works(sentry_init):
565565
)
566566
def test_atexit(tmpdir, monkeypatch, num_messages, http2):
567567
if http2:
568-
options = "http2=True"
568+
options = '_experiments={"transport_http2": True}'
569569
transport = "Http2Transport"
570570
else:
571-
options = "http2=False"
571+
options = ""
572572
transport = "HttpTransport"
573573

574574
app = tmpdir.join("app.py")

tests/test_transport.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_transport_num_pools(make_client, num_pools, expected_num_pools):
213213
if num_pools is not None:
214214
_experiments["transport_num_pools"] = num_pools
215215

216-
client = make_client(_experiments=_experiments)
216+
client = make_client(_experiments=_experiments, http2=False)
217217

218218
options = client.transport._get_pool_options()
219219
assert options["num_pools"] == expected_num_pools
@@ -254,20 +254,20 @@ def test_socket_options(make_client):
254254

255255

256256
def test_keep_alive_true(make_client):
257-
client = make_client(keep_alive=True)
257+
client = make_client(keep_alive=True, http2=False)
258258

259259
options = client.transport._get_pool_options()
260260
assert options["socket_options"] == KEEP_ALIVE_SOCKET_OPTIONS
261261

262262

263263
def test_keep_alive_on_by_default(make_client):
264-
client = make_client()
264+
client = make_client(http2=False)
265265
options = client.transport._get_pool_options()
266266
assert "socket_options" not in options
267267

268268

269269
def test_default_timeout(make_client):
270-
client = make_client()
270+
client = make_client(http2=False)
271271

272272
options = client.transport._get_pool_options()
273273
assert "timeout" in options
@@ -320,19 +320,44 @@ def test_socket_options_override_keep_alive(make_client):
320320
(socket.SOL_TCP, socket.TCP_KEEPCNT, 6),
321321
]
322322

323-
client = make_client(socket_options=socket_options, keep_alive=False)
323+
client = make_client(socket_options=socket_options, keep_alive=False, http2=False)
324324

325325
options = client.transport._get_pool_options()
326326
assert options["socket_options"] == socket_options
327327

328328

329+
@pytest.mark.skipif(not PY38, reason="HTTP2 libraries are only available in py3.8+")
330+
def test_socket_options_merge_with_keep_alive_http2(make_client):
331+
socket_options = [
332+
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 42),
333+
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 42),
334+
]
335+
336+
client = make_client(socket_options=socket_options)
337+
338+
options = client.transport._get_pool_options()
339+
try:
340+
assert options["socket_options"] == [
341+
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 42),
342+
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 42),
343+
(socket.SOL_TCP, socket.TCP_KEEPIDLE, 45),
344+
(socket.SOL_TCP, socket.TCP_KEEPCNT, 6),
345+
]
346+
except AttributeError:
347+
assert options["socket_options"] == [
348+
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 42),
349+
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 42),
350+
(socket.SOL_TCP, socket.TCP_KEEPCNT, 6),
351+
]
352+
353+
329354
def test_socket_options_merge_with_keep_alive(make_client):
330355
socket_options = [
331356
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 42),
332357
(socket.SOL_TCP, socket.TCP_KEEPINTVL, 42),
333358
]
334359

335-
client = make_client(socket_options=socket_options, keep_alive=True)
360+
client = make_client(socket_options=socket_options, keep_alive=True, http2=False)
336361

337362
options = client.transport._get_pool_options()
338363
try:
@@ -350,12 +375,23 @@ def test_socket_options_merge_with_keep_alive(make_client):
350375
]
351376

352377

353-
def test_socket_options_override_defaults(make_client):
378+
@pytest.mark.skipif(not PY38, reason="HTTP2 libraries are only available in py3.8+")
379+
def test_socket_options_override_defaults_http2(make_client):
354380
# If socket_options are set to [], this doesn't mean the user doesn't want
355381
# any custom socket_options, but rather that they want to disable the urllib3
356382
# socket option defaults, so we need to set this and not ignore it.
357383
client = make_client(socket_options=[])
358384

385+
options = client.transport._get_pool_options()
386+
assert options["socket_options"] == KEEP_ALIVE_SOCKET_OPTIONS
387+
388+
389+
def test_socket_options_override_defaults(make_client):
390+
# If socket_options are set to [], this doesn't mean the user doesn't want
391+
# any custom socket_options, but rather that they want to disable the urllib3
392+
# socket option defaults, so we need to set this and not ignore it.
393+
client = make_client(http2=False, socket_options=[])
394+
359395
options = client.transport._get_pool_options()
360396
assert options["socket_options"] == []
361397

0 commit comments

Comments
 (0)