graphql-engine/server/tests-py/run-new.sh
Samir Talwar 7c452bfca1 server/tests-py: Spawn a new PostgreSQL schema ("database") per test.
When running using the "new" style (with a HGE binary, not a URL), a new PostgreSQL metadata and source database are created for each test. When we get this into CI, this should drastically reduce the flakiness.

I have also enabled parallelization by default when using `run-new.sh`. It's much faster.

I had to basically rewrite _server/tests-py/test_graphql_read_only_source.py_ so that it does two different things depending on how it's run. It's unfortunate, but it should eventually go away.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6879
GitOrigin-RevId: a121b9035f8da3e61a3e36d8b1fbc6ccae918fad
2022-11-15 19:08:53 +00:00

60 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# This allows a developer to easily run the Python integration tests using the
# `--hge-bin` flag.
#
# The Pytest runner will start a new HGE instance for each test class, with the
# default arguments and the environment variables provided below.
#
# This is a work in progress.
set -e
set -u
set -o pipefail
cd -- "$(dirname -- "${BASH_SOURCE[0]}")"
DATABASES=(postgres citus sqlserver sqlserver-healthcheck)
(
cd ../..
echo '*** Building HGE ***'
cabal build -j graphql-engine:exe:graphql-engine
echo
echo '*** Installing test dependencies ***'
make server/tests-py/.hasura-dev-python-venv server/tests-py/node_modules remove-tix-file
)
# shellcheck disable=SC1091
source .hasura-dev-python-venv/bin/activate
# Use the Azure SQL Edge image instead of the SQL Server image on arm64.
# The latter doesn't work yet.
if [[ "$(uname -m)" == 'arm64' ]]; then
export MSSQL_IMAGE='mcr.microsoft.com/azure-sql-edge'
fi
echo
echo '*** Pulling images ***'
docker compose pull "${DATABASES[@]}"
echo
echo '*** Starting databases ***'
docker compose up -d --wait "${DATABASES[@]}"
HASURA_GRAPHQL_PG_SOURCE_URL_1="postgresql://postgres:hasura@localhost:$(docker compose port --index 1 postgres 5432 | sed -E 's/.*://')/postgres"
HASURA_GRAPHQL_PG_SOURCE_URL_2="postgresql://postgres:hasura@localhost:$(docker compose port --index 2 postgres 5432 | sed -E 's/.*://')/postgres"
HASURA_GRAPHQL_CITUS_SOURCE_URL="postgresql://postgres:hasura@localhost:$(docker compose port citus 5432 | sed -E 's/.*://')/postgres"
HASURA_GRAPHQL_MSSQL_SOURCE_URL="DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost,$(docker compose port sqlserver 1433 | sed -E 's/.*://');Uid=sa;Pwd=Password!;Encrypt=optional"
export HASURA_GRAPHQL_PG_SOURCE_URL_1 HASURA_GRAPHQL_PG_SOURCE_URL_2 HASURA_GRAPHQL_CITUS_SOURCE_URL HASURA_GRAPHQL_MSSQL_SOURCE_URL
echo
echo '*** Running tests ***'
pytest \
--dist=loadscope \
-n auto \
--hge-bin="$(cabal list-bin graphql-engine:exe:graphql-engine)" \
--pg-urls "$HASURA_GRAPHQL_PG_SOURCE_URL_1" "$HASURA_GRAPHQL_PG_SOURCE_URL_2" \
"$@"