Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions packages/django-google-spanner/django_test_suite_5.2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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}"
Comment on lines +82 to +84

Copy link
Copy Markdown
Contributor

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.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
23 changes: 21 additions & 2 deletions packages/django-google-spanner/django_test_suite_6.0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
2 changes: 1 addition & 1 deletion packages/django-google-spanner/run_testing_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __exit__(self, exc, exc_value, traceback):
suite = os.environ.get("DJANGO_TEST_SUITE", "./django_test_suite_6.0.sh")
with TestInstance() as instance_name:
os.system(
"""DJANGO_TEST_APPS="{apps}" SPANNER_TEST_INSTANCE={instance} bash {suite}""".format(
"""RUNNING_SPANNER_BACKEND_TESTS=1 DJANGO_TEST_APPS="{apps}" SPANNER_TEST_INSTANCE={instance} bash {suite}""".format(
apps=" ".join(test_apps), instance=instance_name, suite=suite
)
)
Loading