From e9aee384b30d5c52201601580e9299b65b257d07 Mon Sep 17 00:00:00 2001 From: Sylvie Date: Wed, 8 May 2024 12:30:38 -0500 Subject: [PATCH 1/3] Use a (local) test DB for load tests so it doesn't wipe out the regular DB --- docker-compose.postgres-test.yml | 23 +++++++++++++++++++++++ load-execute.sh | 6 +++--- 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 docker-compose.postgres-test.yml diff --git a/docker-compose.postgres-test.yml b/docker-compose.postgres-test.yml new file mode 100644 index 000000000..fc47e11b8 --- /dev/null +++ b/docker-compose.postgres-test.yml @@ -0,0 +1,23 @@ +# Run the following to migrate... +# liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary --username intermediary --password 'changeIT!' --label-filter '!azure' + +# Run the following to rollback... +# liquibase rollback-count --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary --username intermediary --password 'changeIT!' --count 2 + +version: "3.7" + +services: + postgresql: + image: postgres:16 + restart: unless-stopped + environment: + POSTGRES_DB: "intermediary-test" + POSTGRES_PASSWORD: "changeIT!" # pragma: allowlist secret + POSTGRES_USER: "intermediary" + ports: + - 5433:5432 + volumes: + - ti_postgres_data:/var/lib/postgresql/data + +volumes: + ti_postgres_data: diff --git a/load-execute.sh b/load-execute.sh index ca81fcd9a..3f0f48c2f 100755 --- a/load-execute.sh +++ b/load-execute.sh @@ -5,7 +5,7 @@ start_api() { echo 'Starting API' export DB_URL=localhost export DB_PORT=5433 - export DB_NAME=intermediary + export DB_NAME=intermediary-test export DB_USER=intermediary export DB_PASS=changeIT! export DB_SSL=require @@ -16,14 +16,14 @@ start_api() { start_database() { echo 'Starting database' - docker compose -f docker-compose.postgres.yml up -d + docker compose -f docker-compose.postgres-test.yml up -d sleep 2 echo "Database started" } migrate_database() { echo 'Migrating database' - liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary --username intermediary --password 'changeIT!' --label-filter '!azure' + liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary-test --username intermediary --password 'changeIT!' --label-filter '!azure' echo "Database migrated" } From ea1fae2efc2fa91bab2b079fa2e60f7ad5940702 Mon Sep 17 00:00:00 2001 From: Sylvie Date: Wed, 8 May 2024 12:43:05 -0500 Subject: [PATCH 2/3] split out the ports and volumes between test and not --- docker-compose.postgres-test.yml | 14 ++++---------- load-execute.sh | 10 +++++----- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/docker-compose.postgres-test.yml b/docker-compose.postgres-test.yml index fc47e11b8..23c3b1804 100644 --- a/docker-compose.postgres-test.yml +++ b/docker-compose.postgres-test.yml @@ -1,13 +1,7 @@ -# Run the following to migrate... -# liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary --username intermediary --password 'changeIT!' --label-filter '!azure' - -# Run the following to rollback... -# liquibase rollback-count --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary --username intermediary --password 'changeIT!' --count 2 - version: "3.7" services: - postgresql: + postgresql-test: image: postgres:16 restart: unless-stopped environment: @@ -15,9 +9,9 @@ services: POSTGRES_PASSWORD: "changeIT!" # pragma: allowlist secret POSTGRES_USER: "intermediary" ports: - - 5433:5432 + - 5434:5432 volumes: - - ti_postgres_data:/var/lib/postgresql/data + - ti_postgres_test_data:/var/lib/postgresql/data volumes: - ti_postgres_data: + ti_postgres_test_data: diff --git a/load-execute.sh b/load-execute.sh index 3f0f48c2f..812e701d5 100755 --- a/load-execute.sh +++ b/load-execute.sh @@ -4,7 +4,7 @@ set -e start_api() { echo 'Starting API' export DB_URL=localhost - export DB_PORT=5433 + export DB_PORT=5434 export DB_NAME=intermediary-test export DB_USER=intermediary export DB_PASS=changeIT! @@ -23,7 +23,7 @@ start_database() { migrate_database() { echo 'Migrating database' - liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary-test --username intermediary --password 'changeIT!' --label-filter '!azure' + liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5434/intermediary-test --username intermediary --password 'changeIT!' --label-filter '!azure' echo "Database migrated" } @@ -54,9 +54,9 @@ cleanup() { kill "${API_PID}" echo "PID ${API_PID} killed" echo "Stopping and deleting database" - docker stop trusted-intermediary-postgresql-1 - docker rm -f trusted-intermediary-postgresql-1 - docker volume rm trusted-intermediary_ti_postgres_data + docker stop trusted-intermediary-postgresql-test-1 + docker rm -f trusted-intermediary-postgresql-test-1 + docker volume rm trusted-intermediary_ti_postgres_test_data echo "Database stopped and deleted" } From 479bdc767202fb35e8ab1579fcd5a63e73ac3676 Mon Sep 17 00:00:00 2001 From: Sylvie Date: Wed, 8 May 2024 12:47:46 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 27edf4f49..fa14542bd 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,8 @@ running... ``` This will run the API for you, so no need to run it manually. +**If you are already running the API, stop it before running the load tests or the cleanup steps won't work.** +The load tests will also spin up (and clean up) a local test DB on port 5434 that should not interfere with the local dev DB. The `locustfile.py` that specifies the load test is located at [`./operations/locustfile.py`](./operations/locustfile.py).