Skip to content
Snippets Groups Projects
Commit e1e4a0df authored by Emanuele Aina's avatar Emanuele Aina
Browse files

test_urls: Use a threadpool for the HTTP requests


Speed up the querying by using a threadpool.

Signed-off-by: Emanuele Aina's avatarEmanuele Aina <emanuele.aina@collabora.com>
parent 5dc9655b
No related branches found
Tags debian/1.1.1n-0+deb11u1
No related merge requests found
...@@ -11,6 +11,8 @@ import sys ...@@ -11,6 +11,8 @@ import sys
import traceback import traceback
from urllib.parse import urlparse from urllib.parse import urlparse
import urllib3 import urllib3
import asyncio
import concurrent.futures
import time import time
import fnmatch import fnmatch
import textwrap import textwrap
...@@ -87,10 +89,7 @@ adapter = requests.adapters.HTTPAdapter(max_retries=3) ...@@ -87,10 +89,7 @@ adapter = requests.adapters.HTTPAdapter(max_retries=3)
session.mount('http://', adapter) session.mount('http://', adapter)
session.mount('https://', adapter) session.mount('https://', adapter)
broken = [] def url_check(url):
for url in urls:
print("%s : " %(url), end='')
sys.stdout.flush()
start = time.perf_counter() start = time.perf_counter()
status = None status = None
resp = None resp = None
...@@ -116,9 +115,15 @@ for url in urls: ...@@ -116,9 +115,15 @@ for url in urls:
print(f"ERROR(2): {url} {resp.status_code if resp else '-'}\n{e_str}") print(f"ERROR(2): {url} {resp.status_code if resp else '-'}\n{e_str}")
end = time.perf_counter() end = time.perf_counter()
if not status:
broken.append(url)
print(url, "OK" if status else "FAIL", resp.status_code if resp else "-", f"{end - start:0.4f}s") print(url, "OK" if status else "FAIL", resp.status_code if resp else "-", f"{end - start:0.4f}s")
return url, status
print(f"Testing {len(urls)} URLs")
with concurrent.futures.ThreadPoolExecutor(max_workers=PARALLEL) as executor:
broken = []
for url, status in executor.map(url_check, urls):
if not status:
broken.append(url)
print(f"Found {len(broken)} broken URLs in {len(urls)} tested:") print(f"Found {len(broken)} broken URLs in {len(urls)} tested:")
for b in broken: for b in broken:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment