Skip to content

Commit 5b84066

Browse files
[py] use get_timeout() for urllib pool manager timeouts in remote connection, prevents passing the default socket object directly (#10563)
* pass the underlying `timeout` to urls pool manager * invoke the `get_timeout()` class method for `urllib` timeouts * fix class state leaking across tests for url lib timeouts; add unit test for default Co-authored-by: David Burns <david.burns@theautomatedtester.co.uk>
1 parent 2c9cbd7 commit 5b84066

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

‎py/selenium/webdriver/remote/remote_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def _seperate_http_proxy_auth(self):
143143

144144
def _get_connection_manager(self):
145145
pool_manager_init_args = {
146-
'timeout': self._timeout
146+
'timeout': self.get_timeout()
147147
}
148148
if self._ca_certs:
149149
pool_manager_init_args['cert_reqs'] = 'CERT_REQUIRED'

‎py/test/unit/selenium/webdriver/remote/remote_connection_tests.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
19-
import urllib3
20-
import pytest
21-
22-
2318
from urllib import parse
2419

20+
import pytest
21+
import urllib3
2522

2623
from selenium import __version__
2724
from selenium.webdriver.remote.remote_connection import (
@@ -96,15 +93,21 @@ def test_get_connection_manager_without_proxy(mock_proxy_settings_missing):
9693
assert type(conn) == urllib3.PoolManager
9794

9895

99-
def test_get_connection_manager_for_certs_and_timeout():
96+
def test_get_connection_manager_for_certs_and_timeout(monkeypatch):
97+
monkeypatch.setattr(RemoteConnection, "get_timeout", lambda _: 10) # Class state; leaks into subsequent tests.
10098
remote_connection = RemoteConnection('http://remote', keep_alive=False)
101-
remote_connection.set_timeout(10)
10299
conn = remote_connection._get_connection_manager()
103100
assert conn.connection_pool_kw['timeout'] == 10
104101
assert conn.connection_pool_kw['cert_reqs'] == 'CERT_REQUIRED'
105102
assert 'certifi/cacert.pem' in conn.connection_pool_kw['ca_certs']
106103

107104

105+
def test_default_socket_timeout_is_correct():
106+
remote_connection = RemoteConnection("http://remote", keep_alive=True)
107+
conn = remote_connection._get_connection_manager()
108+
assert conn.connection_pool_kw['timeout'] is None
109+
110+
108111
def test_get_connection_manager_with_proxy(mock_proxy_settings):
109112
remote_connection = RemoteConnection('http://remote', keep_alive=False)
110113
conn = remote_connection._get_connection_manager()

0 commit comments

Comments
 (0)