Skip to content

Commit

Permalink
Use new setup script in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
JBorrow committed Feb 6, 2024
1 parent 74199c3 commit cb4faa8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 4 additions & 0 deletions librarian_server_scripts/librarian_server_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,7 @@ def main():
exit(1)

log.debug(f"Database user {args.librarian_db_user}, role, and password created.")


if __name__ == "__main__": # pragma: no cover
main()
32 changes: 29 additions & 3 deletions librarian_server_scripts/librarian_server_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,45 @@
you can even run the librarian_background module as a separate instance.
"""

import argparse as ap
import os
import subprocess
import sys
from pathlib import Path

from librarian_background import background
from librarian_server.database import get_session
from librarian_server.logger import log
from librarian_server.orm import StoreMetadata
from librarian_server.settings import server_settings

# Do this in if __name__ == "__main__" so we can spawn threads on MacOS...


def main():
parser = ap.ArgumentParser(
description=(
"Librarian server start. Used to start both the server and "
"background task process simultaneously. If you pass --setup, ",
"it will also run the setup script with the default arguments. "
"This is not recommended for production, but is helpful for testing.",
)
)

parser.add_argument(
"--setup",
action="store_true",
help="Run the setup script before starting the server.",
)

args = parser.parse_args()


def main(setup=args.setup):
if setup:
log.info("Running setup script.")
subprocess.call(
[sys.executable, Path(__file__).parent / "librarian_server_setup.py"],
env=os.environ,
)

# Now we can start the background process thread.
log.info("Starting background process.")

Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def server(xprocess, tmp_path_factory, request) -> Server:

class Starter(ProcessStarter):
pattern = "Uvicorn running on"
args = [sys.executable, shutil.which("librarian-server-start")]
args = [sys.executable, shutil.which("librarian-server-start"), "--setup"]
timeout = 10
env = setup.env

Expand Down

0 comments on commit cb4faa8

Please sign in to comment.