Mercurial > p > roundup > code
changeset 7916:4cca0ae9f901
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 28 Apr 2024 19:24:19 -0400 |
| parents | 82093eb944d6 |
| children | 0b82d42790ae |
| files | test/test_liveserver.py |
| diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_liveserver.py Sun Apr 28 09:55:15 2024 -0400 +++ b/test/test_liveserver.py Sun Apr 28 19:24:19 2024 -0400 @@ -1401,6 +1401,13 @@ 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): @@ -1408,7 +1415,7 @@ 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 ) @@ -1441,7 +1448,7 @@ 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",} @@ -1478,7 +1485,7 @@ # 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",} @@ -1493,7 +1500,7 @@ 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",}
