build(backend): ensure that test scripting returns an error code if s… (#28)

* build(backend): ensure that test scripting returns an error code if steps fail

* build(backend): wait for database to be ready before running migrations

* build(backend): extra sleep after successful healthcheck

* fix(backend): ensure that ci environment expects same DB port as test

* build(backend): better error handling in test script

* build(backend): remove arbitrary sleep
This commit is contained in:
Marc 2023-08-19 12:08:24 -04:00 committed by GitHub
parent 62cb0955d5
commit 52cef95493
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 8 deletions

View file

@ -1,5 +1,5 @@
DATABASE_USERNAME = "postgres"
DATABASE_PASSWORD = "test"
DATABASE_HOST = "localhost"
DATABASE_PORT = 5432
DATABASE_PORT = 5431
DATABASE_NAME = "postgres"

View file

@ -5,8 +5,10 @@
# This is useful if you are not hosting your database instance
# elsewhere or want a simple setup for development purposes.
CONTAINER_NAME=rotini_db
docker run \
--name rotini_db \
--name $CONTAINER_NAME \
-e POSTGRES_PASSWORD=$DATABASE_PASSWORD \
-e POSTGRES_USER=$DATABASE_USER \
-e POSTGRES_DB=$DATABASE_NAME \
@ -15,6 +17,9 @@ docker run \
-d \
postgres:15.4
sleep 3
until [ -n "$(docker exec $CONTAINER_NAME pg_isready | grep accepting)" ]; do
echo "Waiting for DB to come alive..."
sleep 0.1;
done;
PYTHONPATH=rotini .venv/bin/python rotini/migrations/migrate.py up

View file

@ -1,6 +1,7 @@
#!/bin/bash
TEST_DB_CONTAINER=rotini-test-ephemeral
FAILED=0
docker run \
--name $TEST_DB_CONTAINER \
@ -9,10 +10,17 @@ docker run \
-d \
postgres:15.4
sleep 2
until [ -n "$(docker exec $TEST_DB_CONTAINER pg_isready | grep accepting)" ]; do
echo "Waiting for DB to come alive..."
sleep 0.1;
done;
ROTINI_TEST=1 PYTHONPATH=rotini .venv/bin/python rotini/migrations/migrate.py up || echo "Migrations failed."
ROTINI_TEST=1 .venv/bin/pytest . -vv -s || echo "Test run failed."
ROTINI_TEST=1 PYTHONPATH=rotini .venv/bin/python rotini/migrations/migrate.py up || (echo "Migrations failed." && FAILED=1)
ROTINI_TEST=1 .venv/bin/pytest . -vv -s || (echo "Test run failed." && FAILED=1)
docker stop $TEST_DB_CONTAINER > /dev/null || echo "Failed to stop test database container."
docker remove $TEST_DB_CONTAINER > /dev/null || echo "Failed to clean up test database container."
docker rm $TEST_DB_CONTAINER -f > /dev/null || echo "Failed to clean up test database container."
if [ $FAILED -eq 1 ];
then
exit 1
fi