Skip to content

Commit

Permalink
Start our own instance of fpserver for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Dec 2, 2024
1 parent 877388f commit 510242e
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
import requests
import pytest
import subprocess
import socket
from urllib.parse import urljoin


@pytest.fixture(scope='session')
def server_port():
sock = socket.socket()
sock.bind(('', 0))
return sock.getsockname()[1]


@pytest.fixture(scope='session')
def server(server_port, tmp_path_factory):
tmp_dir = tmp_path_factory.mktemp("server")
data_dir = tmp_dir / 'data'
stderr = tmp_dir / 'server.stderr.log'
command = [
'zig-out/bin/fpindex',
'--dir', str(data_dir),
'--port', str(server_port),
'--log-level', 'debug',
]
process = subprocess.Popen(
command,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=stderr.open('w'),
)
yield
process.terminate()
retcode = process.wait()
if retcode != 0:
for line in stderr.read_text().splitlines():
print(line)


@pytest.fixture
def index_name():
return 'testidx'
Expand Down Expand Up @@ -36,8 +70,8 @@ def session():


@pytest.fixture
def client(session):
return Client(session, 'http://localhost:8080')
def client(session, server_port, server):
return Client(session, f'http://localhost:{server_port}')


@pytest.fixture(autouse=True)
Expand Down

0 comments on commit 510242e

Please sign in to comment.