@@ -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
256256def 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
263263def 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
269269def 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+
329354def 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