Skip to content

Commit

Permalink
Revert "run fractal-server as an external service"
Browse files Browse the repository at this point in the history
This reverts commit 6d00f55.
  • Loading branch information
ychiucco committed Oct 24, 2024
1 parent ecc2e3d commit 0e00b42
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
ports:
- 5432:5432


steps:

- uses: actions/checkout@v4
Expand All @@ -48,9 +47,6 @@ jobs:
- name: Install dependencies
run: poetry install --with dev --without docs --no-interaction

- name: Run fractal-server
run: sh tests/serve.sh > /dev/null 2>&1 &

- name: Test with pytest
env:
COVERAGE_FILE: coverage-data-${{ matrix.python-version }}
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ fractal.log
site
reference
venv
FRACTAL_TASK_DIR/*
FRACTAL_RUNNER_WORKING_BASE_DIR/*
67 changes: 65 additions & 2 deletions tests/fixtures_testserver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import logging
import shlex
import subprocess
import time
from pathlib import Path
from typing import Optional

import pytest
Expand All @@ -13,6 +15,8 @@
logger = logging.getLogger("fractal-client")
logger.setLevel(logging.DEBUG)

PORT = 8765


@pytest.fixture
def superuser(invoke_as_superuser):
Expand All @@ -24,8 +28,58 @@ 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):
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,
)

# Wait until the server is up
TIMEOUT = 8
Expand Down Expand Up @@ -55,7 +109,16 @@ def testserver(tester):
)
)
)
yield

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()


@pytest.fixture
Expand Down

0 comments on commit 0e00b42

Please sign in to comment.