Skip to content

Commit f6d473d

Browse files
committed
issue2551334 - get test suite running under windows
https://stackoverflow.com/questions/59506097/python-requests-library-is-very-slow-on-windows/75425238#75425238 reports that the requests libary uses urllib3. On windows this tries (and retries) an IPv6 address if localhost is used in the url. This takes 2s per request to test IPv6, give up and use IPv4. At that rate, the rate limit is never reached and the rest_login_RateLimit test fails. This patch rewrites the base url to use 127.0.0.1 replacing localhost. It forced urllib3 to open only an IPv4 address and the speedup allows the test to pass.
1 parent 389d493 commit f6d473d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

test/test_liveserver.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,14 +1401,21 @@ def test_rest_login_RateLimit(self):
14011401
logins count though. So log in 10 times in a row
14021402
to verify that valid username/passwords aren't limited.
14031403
"""
1404+
# On windows, using localhost in the URL with requests
1405+
# tries an IPv6 address first. This causes a request to
1406+
# take 2 seconds which is too slow to ever trip the rate
1407+
# limit. So replace localhost with 127.0.0.1 that does an
1408+
# IPv4 request only.
1409+
url_base_numeric = self.url_base()
1410+
url_base_numeric = url_base_numeric.replace('localhost','127.0.0.1')
14041411

14051412
# verify that valid logins are not counted against the limit.
14061413
for i in range(10):
14071414
# use basic auth for rest endpoint
14081415

14091416
request_headers = {'content-type': "",
14101417
'Origin': "http://localhost:9001",}
1411-
f = requests.options(self.url_base() + '/rest/data',
1418+
f = requests.options(url_base_numeric + '/rest/data',
14121419
auth=('admin', 'sekrit'),
14131420
headers=request_headers
14141421
)
@@ -1441,7 +1448,7 @@ def test_rest_login_RateLimit(self):
14411448
for i in range(10):
14421449
# use basic auth for rest endpoint
14431450

1444-
f = requests.options(self.url_base() + '/rest/data',
1451+
f = requests.options(url_base_numeric + '/rest/data',
14451452
auth=('admin', 'ekrit'),
14461453
headers = {'content-type': "",
14471454
'Origin': "http://localhost:9001",}
@@ -1478,7 +1485,7 @@ def test_rest_login_RateLimit(self):
14781485

14791486
# test lockout this is a valid login but should be rejected
14801487
# with 429.
1481-
f = requests.options(self.url_base() + '/rest/data',
1488+
f = requests.options(url_base_numeric + '/rest/data',
14821489
auth=('admin', 'sekrit'),
14831490
headers = {'content-type': "",
14841491
'Origin': "http://localhost:9001",}
@@ -1493,7 +1500,7 @@ def test_rest_login_RateLimit(self):
14931500
sleep(4)
14941501
# slept long enough to get a login slot. Should work with
14951502
# 200 return code.
1496-
f = requests.get(self.url_base() + '/rest/data',
1503+
f = requests.get(url_base_numeric + '/rest/data',
14971504
auth=('admin', 'sekrit'),
14981505
headers = {'content-type': "",
14991506
'Origin': "http://localhost:9001",}

0 commit comments

Comments
 (0)