Repository navigation
test(django-google-spanner): run live Spanner test apps in parallel with unique DB per app #18983
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,15 +27,8 @@ export PYTHONPATH=$PYTHONPATH:$(pwd):$(pwd)/$DJANGO_TESTS_DIR/django | |
|
|
||
| python3 create_test_instance.py | ||
|
|
||
| # If no SPANNER_TEST_DB is set, generate a unique one | ||
| # so that we can have multiple tests running without | ||
| # conflicting which changes and constraints. We'll always | ||
| # cleanup the created database. | ||
| TEST_DBNAME=${SPANNER_TEST_DB:-$(python3 -c 'import os, time; print(chr(ord("a") + time.time_ns() % 26)+os.urandom(10).hex())')} | ||
| TEST_DBNAME_OTHER="$TEST_DBNAME-ot" | ||
| INSTANCE=${SPANNER_TEST_INSTANCE:-spanner-django-python-systest} | ||
| PROJECT=${PROJECT_ID:-$GOOGLE_CLOUD_PROJECT} | ||
| SETTINGS_FILE="$TEST_DBNAME-settings" | ||
| TESTS_DIR=${DJANGO_TESTS_DIR:-django_tests} | ||
|
|
||
| create_settings() { | ||
|
|
@@ -75,15 +68,35 @@ INSTALLED_APPS = [ | |
| } | ||
|
|
||
| cd $TESTS_DIR/django/tests | ||
| create_settings | ||
|
|
||
| EXIT_STATUS=0 | ||
| PIDS="" | ||
| for DJANGO_TEST_APP in $DJANGO_TEST_APPS | ||
| do | ||
| if [ "$DJANGO_TEST_APP" = "order_with_respect_to" ] || [ "$DJANGO_TEST_APP" = "contenttypes_tests" ] || [ "$DJANGO_TEST_APP" = "inspectdb" ]; then | ||
| echo "Skipping $DJANGO_TEST_APP as it is incompatible with Spanner" | ||
| continue | ||
| fi | ||
| python3 runtests.py $DJANGO_TEST_APP --verbosity=3 --noinput --settings $SETTINGS_FILE || EXIT_STATUS=$? | ||
| APP_PREFIX=$(echo "$DJANGO_TEST_APP" | tr -cd 'a-z0-9' | cut -c1-6) | ||
| RUN_ID=$(python3 -c 'import os; print(os.urandom(6).hex())') | ||
| if [ -n "$SPANNER_TEST_DB" ]; then | ||
| DB_PREFIX=$(echo "$SPANNER_TEST_DB" | cut -c1-20) | ||
| TEST_DBNAME="${DB_PREFIX}_${APP_PREFIX}" | ||
| else | ||
| TEST_DBNAME="${APP_PREFIX}_${RUN_ID}" | ||
| fi | ||
| TEST_DBNAME_OTHER="${TEST_DBNAME}-ot" | ||
| SETTINGS_FILE="${TEST_DBNAME}_settings" | ||
|
Comment on lines
+80
to
+89
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that there is a high risk of name collisions here. Also, won't all of the tests use the same DB name if SPANNER_TEST_DB is set? |
||
| create_settings | ||
| if [ -z "$SPANNER_EMULATOR_HOST" ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The GitHub pull request checks set SPANNER_EMULATOR_HOST, so the non-emulator path is never tested for this pull request. And I think that the intention to limit the concurrency to max 4 does not actually work if you run this on real Spanner (or if you were to enable concurrency on the Emulator). |
||
| python3 runtests.py "$DJANGO_TEST_APP" --verbosity=3 --noinput --settings "$SETTINGS_FILE" & | ||
| PIDS="$PIDS $!" | ||
| else | ||
| python3 runtests.py "$DJANGO_TEST_APP" --verbosity=3 --noinput --settings "$SETTINGS_FILE" || EXIT_STATUS=$? | ||
| fi | ||
| done | ||
| for PID in $PIDS | ||
| do | ||
| wait "$PID" || EXIT_STATUS=$? | ||
| done | ||
| exit $EXIT_STATUS | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,15 +76,34 @@ INSTALLED_APPS = [ | |
| } | ||
|
|
||
| cd $TESTS_DIR/django/tests | ||
| create_settings | ||
|
|
||
| EXIT_STATUS=0 | ||
| PIDS="" | ||
| for DJANGO_TEST_APP in $DJANGO_TEST_APPS | ||
| do | ||
| if [ "$DJANGO_TEST_APP" = "order_with_respect_to" ] || [ "$DJANGO_TEST_APP" = "contenttypes_tests" ] || [ "$DJANGO_TEST_APP" = "inspectdb" ]; then | ||
| echo "Skipping $DJANGO_TEST_APP as it is incompatible with Spanner" | ||
| continue | ||
| fi | ||
| python3 runtests.py $DJANGO_TEST_APP --verbosity=3 --noinput --settings $SETTINGS_FILE || EXIT_STATUS=$? | ||
| APP_PREFIX=$(echo "$DJANGO_TEST_APP" | tr -cd 'a-z0-9' | cut -c1-6) | ||
| RUN_ID=$(python3 -c 'import os; print(os.urandom(6).hex())') | ||
| if [ -n "$SPANNER_TEST_DB" ]; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will also fail if the database name length is too long (here we do not even try to truncate it) |
||
| TEST_DBNAME="${SPANNER_TEST_DB}_${APP_PREFIX}" | ||
| else | ||
| TEST_DBNAME="${APP_PREFIX}_${RUN_ID}" | ||
| fi | ||
| TEST_DBNAME_OTHER="${TEST_DBNAME}-ot" | ||
| SETTINGS_FILE="${TEST_DBNAME}_settings" | ||
| create_settings | ||
| if [ -z "$SPANNER_EMULATOR_HOST" ]; then | ||
| python3 runtests.py "$DJANGO_TEST_APP" --verbosity=3 --noinput --settings "$SETTINGS_FILE" & | ||
| PIDS="$PIDS $!" | ||
| else | ||
| python3 runtests.py "$DJANGO_TEST_APP" --verbosity=3 --noinput --settings "$SETTINGS_FILE" || EXIT_STATUS=$? | ||
| fi | ||
| done | ||
| for PID in $PIDS | ||
| do | ||
| wait "$PID" || EXIT_STATUS=$? | ||
| done | ||
| exit $EXIT_STATUS | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this still risks exceeding the 30 char limit for a database name, as Django adds a 'test_' prefix for the database names.