graphql-engine/server/tests-py/run.sh
Samir Talwar 44ad07eeab server/tests-py: Fix up the Redis tests so they run.
This fixes the existing tests around query caching and other Redis-related behaviors so they actually run.

Some of the tests still fail because of a couple of bugs, but the error messages are now meaningful.

They do not yet run in CI. We will enable them once they are fixed.

I added a bit of extra logging; we now log the Redis server host and port. I also left in the `Show` instance derivations I used for debugging, as I don't think they'll harm anything and might be useful in the future.

The changes are as follows:

1. I added a `redis` server to the tests and configured both HGE and the test runner to talk to it.
2. I fixed up the action tests so they set up and tear down correctly, including a fix to the output type of the action.
3. Caching has been implemented for actions with client header forwarding, so I have changed the test accordingly.
4. Tests now fail correctly if the response headers are wrong but the body is correct.
5. I have updated the keys in the response headers as the algorithm for generating them seems to have changed.
6. A few improvements have been made to the Python tests to handle lint warnings and improve logging.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10839
GitOrigin-RevId: 5d31a376346190b5c7b398b4dee84b88a9d1b18b
2024-05-28 15:12:10 +00:00

65 lines
2.2 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 redis)
# If `HGE_BIN` is not set, build and use `graphql-engine:exe:graphql-engine`
if [[ -z "${HGE_BIN:-}" ]]; then
(
cd ../..
echo '*** Building HGE ***'
cabal build graphql-engine:exe:graphql-engine
echo
)
HGE_BIN="$(cabal list-bin graphql-engine:exe:graphql-engine)"
fi
(
echo '*** Installing test dependencies ***'
make -C ../.. 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
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"
HASURA_GRAPHQL_REDIS_URL="redis://localhost:$(docker compose port redis 6379 | sed -E 's/.*://')/"
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 ***'
export SQLALCHEMY_SILENCE_UBER_WARNING=1 # disable warnings about upgrading to SQLAlchemy 2.0
COMMAND=(
pytest
--dist=loadscope
-n auto
--hge-bin="$HGE_BIN"
--pg-urls "$HASURA_GRAPHQL_PG_SOURCE_URL_1" "$HASURA_GRAPHQL_PG_SOURCE_URL_2"
--redis-url "$HASURA_GRAPHQL_REDIS_URL"
"$@"
)
echo '+' "${COMMAND[@]}"
"${COMMAND[@]}"