-
Notifications
You must be signed in to change notification settings - Fork 342
test: add script to run DB integration tests locally #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+133
−0
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e41fc94
test: add script to run integration tests locally
ishymko ec0a7d1
Rewrite in Python
ishymko 2aee10c
Revert "Rewrite in Python"
ishymko e62a0cf
Spelling
ishymko a28bef7
Add script back
ishymko babbe54
+x
ishymko 44face0
Env vars in debug mode
ishymko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| services: | ||
| postgres: | ||
| image: postgres:15-alpine | ||
| environment: | ||
| POSTGRES_USER: a2a | ||
| POSTGRES_PASSWORD: a2a_password | ||
| POSTGRES_DB: a2a_test | ||
| ports: | ||
| - "5432:5432" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "pg_isready"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| mysql: | ||
| image: mysql:8.0 | ||
| environment: | ||
| MYSQL_ROOT_PASSWORD: root | ||
| MYSQL_DATABASE: a2a_test | ||
| MYSQL_USER: a2a | ||
| MYSQL_PASSWORD: a2a_password | ||
| ports: | ||
| - "3306:3306" | ||
| healthcheck: | ||
| test: ["CMD-SHELL", "mysqladmin ping -h localhost -u root -proot"] | ||
| interval: 10s | ||
| timeout: 5s | ||
| retries: 5 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Get the directory of this script | ||
| SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
| PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" | ||
|
|
||
| # Docker compose file path | ||
| COMPOSE_FILE="$SCRIPT_DIR/docker-compose.test.yml" | ||
|
|
||
| # Initialize variables | ||
| DEBUG_MODE=false | ||
| STOP_MODE=false | ||
| SERVICES=() | ||
| PYTEST_ARGS=() | ||
|
|
||
| # Parse arguments | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| --debug) | ||
| DEBUG_MODE=true | ||
| shift | ||
| ;; | ||
| --stop) | ||
| STOP_MODE=true | ||
| shift | ||
| ;; | ||
| --postgres) | ||
| SERVICES+=("postgres") | ||
| shift | ||
| ;; | ||
| --mysql) | ||
| SERVICES+=("mysql") | ||
| shift | ||
| ;; | ||
| *) | ||
| # Preserve other arguments for pytest | ||
| PYTEST_ARGS+=("$1") | ||
| shift | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # Handle --stop | ||
| if [[ "$STOP_MODE" == "true" ]]; then | ||
| echo "Stopping test databases..." | ||
| docker compose -f "$COMPOSE_FILE" down | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Default to running both databases if none specified | ||
| if [[ ${#SERVICES[@]} -eq 0 ]]; then | ||
| SERVICES=("postgres" "mysql") | ||
| fi | ||
|
|
||
| # Cleanup function to stop docker containers | ||
| cleanup() { | ||
| echo "Stopping test databases..." | ||
| docker compose -f "$COMPOSE_FILE" down | ||
| } | ||
|
|
||
| # Start the databases | ||
| echo "Starting/Verifying databases: ${SERVICES[*]}..." | ||
| docker compose -f "$COMPOSE_FILE" up -d --wait "${SERVICES[@]}" | ||
|
|
||
| # Set up environment variables based on active services | ||
| # Only export DSNs for started services so tests skip missing ones | ||
| for service in "${SERVICES[@]}"; do | ||
| if [[ "$service" == "postgres" ]]; then | ||
| export POSTGRES_TEST_DSN="postgresql+asyncpg://a2a:a2a_password@localhost:5432/a2a_test" | ||
| elif [[ "$service" == "mysql" ]]; then | ||
| export MYSQL_TEST_DSN="mysql+aiomysql://a2a:a2a_password@localhost:3306/a2a_test" | ||
| fi | ||
| done | ||
|
|
||
| # Handle --debug mode | ||
| if [[ "$DEBUG_MODE" == "true" ]]; then | ||
| echo "---------------------------------------------------" | ||
| echo "Debug mode enabled. Databases are running." | ||
| echo "You can connect to them using the following DSNs." | ||
| echo "" | ||
| echo "Run the following commands to set up your environment:" | ||
| echo "" | ||
| [[ -n "$POSTGRES_TEST_DSN" ]] && echo "export POSTGRES_TEST_DSN=\"$POSTGRES_TEST_DSN\"" | ||
| [[ -n "$MYSQL_TEST_DSN" ]] && echo "export MYSQL_TEST_DSN=\"$MYSQL_TEST_DSN\"" | ||
| echo "" | ||
| echo "---------------------------------------------------" | ||
| echo "Run ./scripts/run_integration_tests.sh --stop to shut databases down." | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Register cleanup trap for normal test run | ||
| trap cleanup EXIT | ||
|
|
||
| # Run the tests | ||
| echo "Running integration tests..." | ||
| cd "$PROJECT_ROOT" | ||
|
|
||
| uv run --extra all pytest -v \ | ||
| tests/server/tasks/test_database_task_store.py \ | ||
| tests/server/tasks/test_database_push_notification_config_store.py \ | ||
| "${PYTEST_ARGS[@]}" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.