Skip to content

Commit

Permalink
test: add a script to run test servers
Browse files Browse the repository at this point in the history
Instead of trying to use bash directly, run the test servers using a
script. This works around quoting and path resolution issues.
  • Loading branch information
apotterri committed Mar 14, 2024
1 parent 0ceff4c commit de56f67
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
7 changes: 7 additions & 0 deletions _appmap/test/bin/runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -ex

cd "$1"; shift

exec $@
8 changes: 4 additions & 4 deletions _appmap/test/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ def startup_check(self):
pass
return False

terminate_on_interrupt = True
pattern = f"server at http://{host}:{port}"
args = [
"bash",
"-ec",
f"cd {Path(__file__).parent / 'data'/ 'django'};"
+ f" {sys.executable} manage.py runserver"
+ f" {host}:{port}",
Path(__file__).parent / "bin" / "runner",
(Path(__file__).parent / "data" / "django").as_posix(),
f"{Path(sys.executable).as_posix()} manage.py runserver {host}:{port}",
]
env = {
"DJANGO_SETTINGS_MODULE": f"djangoapp.{settings}",
Expand Down
8 changes: 5 additions & 3 deletions _appmap/test/test_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,16 @@ def startup_check(self):
pass
return False

timeout = 10
terminate_on_interrupt = True
pattern = f"Uvicorn running on http://{host}:{port}"
# Can't set popen_kwargs["cwd"] until
# https:/pytest-dev/pytest-xprocess/issues/89 is fixed.
args = [
"bash",
"-ec",
f"cd {Path(__file__).parent / 'data'/ 'fastapi'};"
+ f" {sys.executable} -m uvicorn fastapiapp.main:app"
Path(__file__).parent / "bin" / "runner",
(Path(__file__).parent / "data" / "fastapi").as_posix(),
f"{Path(sys.executable).as_posix()} -m uvicorn fastapiapp.main:app"
+ f" {reload} --host {host} --port {port}",
]
env = {
Expand Down
12 changes: 7 additions & 5 deletions _appmap/test/test_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,26 @@ def startup_check(self):
pass
return False

terminate_on_interrupt = True
pattern = f"Running on http://{host}:{port}"
args = [
"bash",
"-ec",
f"cd {Path(__file__).parent / 'data'/ 'flask'};"
+ f" {sys.executable} -m flask run"
+ f" -p {port}",
Path(__file__).parent / "bin" / "runner",
(Path(__file__).parent / "data" / "flask").as_posix(),
f" {Path(sys.executable).as_posix()} -m flask run -p {port}",
]
print(args)
env = {
"APPMAP_DISABLE_LOG_FILE": "false",
"FLASK_APP": "flaskapp.py",
"FLASK_DEBUG": flask_debug,
"PYTHONUNBUFFERED": "1",
"APPMAP_OUTPUT_DIR": "/tmp",
**server_env,
}

xprocess.ensure("myserver", Starter)
pid, logpath = xprocess.ensure("myserver", Starter)
print(f"pid: {pid} logpath: {logpath}")
yield NS(debug=debug, url=f"http://{host}:{port}")
xprocess.getinfo("myserver").terminate()

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ commands =
# out of the agent confuse poetry.
env APPMAP_LOG_LEVEL=warning APPMAP=false poetry install -v
py310-web: bash -c "poetry run pylint -j 0 appmap _appmap || pylint-exit $?"
web: poetry run {posargs:pytest}
web: poetry run {posargs:pytest -v}
django3: poetry run pytest _appmap/test/test_django.py
flask2: poetry run pytest _appmap/test/test_flask.py

Expand Down

0 comments on commit de56f67

Please sign in to comment.