-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
run fractal-server as an external service
- Loading branch information
Showing
4 changed files
with
23 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ fractal.log | |
site | ||
reference | ||
venv | ||
FRACTAL_TASK_DIR/* | ||
FRACTAL_RUNNER_WORKING_BASE_DIR/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
import logging | ||
import shlex | ||
import subprocess | ||
import time | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
import pytest | ||
|
@@ -15,8 +13,6 @@ | |
logger = logging.getLogger("fractal-client") | ||
logger.setLevel(logging.DEBUG) | ||
|
||
PORT = 8765 | ||
|
||
|
||
@pytest.fixture | ||
def superuser(invoke_as_superuser): | ||
|
@@ -28,58 +24,8 @@ def tester(): | |
return dict(email="[email protected]", password="pytest") | ||
|
||
|
||
def _run_command(cmd: str) -> str: | ||
logging.warning(f"Now running {cmd=}") | ||
res = subprocess.run( | ||
shlex.split(cmd), | ||
capture_output=True, | ||
encoding="utf-8", | ||
) | ||
if res.returncode != 0: | ||
logging.error(f"{res.stdout=}") | ||
logging.error(f"{res.stderr=}") | ||
raise RuntimeError(res.stderr) | ||
else: | ||
return res.stdout | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def testserver(tester, tmpdir_factory): | ||
|
||
FRACTAL_TASK_DIR = str(tmpdir_factory.mktemp("FRACTAL_TASK_DIR")) | ||
FRACTAL_RUNNER_WORKING_BASE_DIR = str( | ||
tmpdir_factory.mktemp("FRACTAL_RUNNER_WORKING_BASE_DIR") | ||
) | ||
|
||
env_file = Path(".fractal_server.env") | ||
with env_file.open("w") as f: | ||
f.write( | ||
"DB_ENGINE=postgres-psycopg\n" | ||
"POSTGRES_HOST=localhost\n" | ||
f"POSTGRES_DB={DB_NAME}\n" | ||
"POSTGRES_USER=postgres\n" | ||
"POSTGRES_PASSWORD=postgres\n" | ||
"FRACTAL_RUNNER_BACKEND=local\n" | ||
"JWT_SECRET_KEY=secret_key\n" | ||
f"FRACTAL_TASKS_DIR={FRACTAL_TASK_DIR}\n" | ||
"FRACTAL_RUNNER_WORKING_BASE_DIR=" | ||
f"{FRACTAL_RUNNER_WORKING_BASE_DIR}\n" | ||
"FRACTAL_LOGGING_LEVEL=0\n" | ||
) | ||
_run_command( | ||
f"dropdb --username=postgres --host localhost --if-exists {DB_NAME}" | ||
) | ||
_run_command(f"createdb --username=postgres --host localhost {DB_NAME}") | ||
_run_command("poetry run fractalctl set-db") | ||
|
||
LOGS = tmpdir_factory.mktemp("LOGS") | ||
f_out = (LOGS / "out").open("w") | ||
f_err = (LOGS / "err").open("w") | ||
server_process = subprocess.Popen( | ||
shlex.split(f"poetry run fractalctl start --port {PORT}"), | ||
stdout=f_out, | ||
stderr=f_err, | ||
) | ||
def testserver(tester): | ||
|
||
# Wait until the server is up | ||
TIMEOUT = 8 | ||
|
@@ -109,16 +55,7 @@ def testserver(tester, tmpdir_factory): | |
) | ||
) | ||
) | ||
|
||
try: | ||
yield | ||
finally: | ||
server_process.terminate() | ||
server_process.kill() | ||
_run_command(f"dropdb --username=postgres --host localhost {DB_NAME}") | ||
env_file.unlink() | ||
f_out.close() | ||
f_err.close() | ||
yield | ||
|
||
|
||
@pytest.fixture | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/sh | ||
|
||
export DB_ENGINE=postgres-psycopg | ||
export POSTGRES_HOST=localhost | ||
export POSTGRES_DB=pytest-fractal-client | ||
export POSTGRES_USER=postgres | ||
export POSTGRES_PASSWORD=postgres | ||
export FRACTAL_RUNNER_BACKEND=local | ||
export JWT_SECRET_KEY=secret_key | ||
export FRACTAL_TASKS_DIR=FRACTAL_TASK_DIR | ||
export FRACTAL_RUNNER_WORKING_BASE_DIR=FRACTAL_RUNNER_WORKING_BASE_DIR | ||
export FRACTAL_LOGGING_LEVEL=0 | ||
|
||
poetry run fractalctl set-db | ||
poetry run fractalctl start --port 8765 > /dev/null 2>&1 & |