From f6d473d27689ddcaf68bf1a2801045834ea3c8d9 Mon Sep 17 00:00:00 2001 From: John Rouillard Date: Sun, 28 Apr 2024 19:24:19 -0400 Subject: [PATCH] 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. --- test/test_liveserver.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/test/test_liveserver.py b/test/test_liveserver.py index 459b1e95..7c329288 100644 --- a/test/test_liveserver.py +++ b/test/test_liveserver.py @@ -1401,6 +1401,13 @@ 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): @@ -1408,7 +1415,7 @@ def test_rest_login_RateLimit(self): 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 @@ 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",} @@ -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",} @@ -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",}