2024-01-25 15:00:07 +00:00
|
|
|
import http.server
|
2023-08-09 12:32:27 +02:00
|
|
|
import pytest
|
2024-01-25 15:00:07 +00:00
|
|
|
import socketserver
|
|
|
|
|
import threading
|
2024-10-31 18:30:41 +01:00
|
|
|
import os
|
2023-08-09 12:32:27 +02:00
|
|
|
|
|
|
|
|
|
2024-10-31 18:30:41 +01:00
|
|
|
HTTP_SERVER_HOST = os.environ.get("HTTP_SERVER_HOST", "localhost")
|
|
|
|
|
|
2023-08-09 12:32:27 +02:00
|
|
|
@pytest.fixture(params=[False, True], scope="module")
|
|
|
|
|
def on_disk_vectors(request):
|
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(params=[False, True], scope="module")
|
|
|
|
|
def on_disk_payload(request):
|
|
|
|
|
return request.param
|
2024-01-25 15:00:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
|
def http_server(tmpdir):
|
|
|
|
|
"""
|
|
|
|
|
Starts a HTTP server serving files from a temporary directory.
|
|
|
|
|
Yields a tuple (tmpdir, url).
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
class Handler(http.server.SimpleHTTPRequestHandler):
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
# Serve files from the temporary directory
|
|
|
|
|
super().__init__(*args, directory=str(tmpdir), **kwargs)
|
|
|
|
|
|
|
|
|
|
def log_request(self, *args, **kwargs):
|
|
|
|
|
# Silence logging
|
|
|
|
|
pass
|
|
|
|
|
|
2024-10-31 18:30:41 +01:00
|
|
|
with socketserver.TCPServer(("0.0.0.0", 0), Handler) as httpd:
|
2024-01-25 15:00:07 +00:00
|
|
|
httpd.allow_reuse_address = True
|
|
|
|
|
thread = threading.Thread(
|
|
|
|
|
target=httpd.serve_forever,
|
|
|
|
|
# Lower the shutdown poll interval to speed up tests
|
|
|
|
|
kwargs={"poll_interval": 0.1},
|
|
|
|
|
)
|
|
|
|
|
thread.start()
|
2024-10-31 18:30:41 +01:00
|
|
|
yield (tmpdir, f"http://{HTTP_SERVER_HOST}:{httpd.server_address[1]}")
|
2024-01-25 15:00:07 +00:00
|
|
|
httpd.shutdown()
|
|
|
|
|
thread.join()
|
2024-11-06 20:09:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='module', autouse=True)
|
|
|
|
|
def collection_name(request):
|
|
|
|
|
return request.node.name.removesuffix(".py")
|