Skip to content

Commit

Permalink
issue2551334 - get test suite running under windows
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rouilj committed Apr 28, 2024
1 parent 389d493 commit f6d473d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions test/test_liveserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1401,14 +1401,21 @@ def test_rest_login_RateLimit(self):
logins count though. So log in 10 times in a row
to verify that valid username/passwords aren't limited.
"""
# On windows, using localhost in the URL with requests
# tries an IPv6 address first. This causes a request to
# take 2 seconds which is too slow to ever trip the rate
# limit. So replace localhost with 127.0.0.1 that does an
# IPv4 request only.
url_base_numeric = self.url_base()
url_base_numeric = url_base_numeric.replace('localhost','127.0.0.1')

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

request_headers = {'content-type': "",
'Origin': "http://localhost:9001",}
f = requests.options(self.url_base() + '/rest/data',
f = requests.options(url_base_numeric + '/rest/data',
auth=('admin', 'sekrit'),
headers=request_headers
)
Expand Down Expand Up @@ -1441,7 +1448,7 @@ def test_rest_login_RateLimit(self):
for i in range(10):
# use basic auth for rest endpoint

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

# test lockout this is a valid login but should be rejected
# with 429.
f = requests.options(self.url_base() + '/rest/data',
f = requests.options(url_base_numeric + '/rest/data',
auth=('admin', 'sekrit'),
headers = {'content-type': "",
'Origin': "http://localhost:9001",}
Expand All @@ -1493,7 +1500,7 @@ def test_rest_login_RateLimit(self):
sleep(4)
# slept long enough to get a login slot. Should work with
# 200 return code.
f = requests.get(self.url_base() + '/rest/data',
f = requests.get(url_base_numeric + '/rest/data',
auth=('admin', 'sekrit'),
headers = {'content-type': "",
'Origin': "http://localhost:9001",}
Expand Down

0 comments on commit f6d473d

Please sign in to comment.