Files
qdrant/tests/openapi/conftest.py
Predrag Knezevic 6f23975e3e Enable running integration tests against non-localhost available instance (#5345)
* `QDRANT_HOST` variable is used by all openapi tests, removed its copies from
  `test_multi_vector_uint8.py`, `test_multi_vector_unnamed.py`, `test_query.py`,
  `test_shard_snapshot.py`, and `test_snapshot.py`
* Added optional `QDRANT_HOST_HEADERS` env variable to set custom HTTP headers
  in order to reach Qdrant instance behind a reverse proxy. The content of the
  variable is JSON payload, e.g. `{"host": "qdrant.local"}`
* Adapted `./tests/basic_*.sh` scripts to aware of `QDRANT_HOST_HEADERS` env variable
2024-11-08 11:21:36 +01:00

47 lines
1.3 KiB
Python

import http.server
import pytest
import socketserver
import threading
import os
HTTP_SERVER_HOST = os.environ.get("HTTP_SERVER_HOST", "localhost")
@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
@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
with socketserver.TCPServer(("0.0.0.0", 0), Handler) as httpd:
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()
yield (tmpdir, f"http://{HTTP_SERVER_HOST}:{httpd.server_address[1]}")
httpd.shutdown()
thread.join()