test: furl: Cap time spent waiting for HTTP requests

Without an explicit timeout, urllib will wait indefinitely for a
connection to be made.
This commit is contained in:
Tobias Waldekranz
2024-05-17 23:42:18 +02:00
parent 57b18a0364
commit 6a6d290ccc
+2 -2
View File
@@ -9,10 +9,10 @@ class Furl:
"""Create new URL checker"""
self.url = urllib.parse.quote(url, safe='/:')
def check(self, needle):
def check(self, needle, timeout=10):
"""Connect to web server URL, fetch body and check for needle"""
try:
with urllib.request.urlopen(self.url) as response:
with urllib.request.urlopen(self.url, timeout=timeout) as response:
text = response.read().decode('utf-8')
#print(text)
return needle in text