From 41908936cfb96a4fe13dc5efcf01d38c7e17839d Mon Sep 17 00:00:00 2001 From: Abby Sassel <3883855+sassela@users.noreply.github.com> Date: Tue, 25 May 2021 14:54:18 +0100 Subject: [PATCH] server: improve backend-specific test setup GitOrigin-RevId: c40393bcdd78feaba7e9490ce4ed78de19b5bfc5 --- scripts/dev.sh | 83 ++++--- scripts/parse-pytest-backend | 49 ++++ server/CONTRIBUTING.md | 4 +- server/tests-py/conftest.py | 22 +- server/tests-py/context.py | 8 +- .../tests-py/queries/explain/setup_mssql.yaml | 1 + .../queries/explain/teardown_mssql.yaml | 8 +- .../basic/schema_teardown_mssql.yaml | 5 +- .../graphql_query/basic/setup_citus.yaml | 5 +- .../graphql_query/basic/setup_mssql.yaml | 13 +- .../graphql_query/basic/teardown_citus.yaml | 54 +++- .../graphql_query/basic/teardown_mssql.yaml | 56 +++-- ...setup_invalid_fkey_relationship_mssql.yaml | 7 + .../boolexp/basic/setup_mssql.yaml | 230 +++++++++--------- .../boolexp/basic/teardown_mssql.yaml | 64 ++++- .../boolexp/search/teardown_mssql.yaml | 26 +- .../boolexp/spatial/teardown_mssql.yaml | 16 +- .../setup_invalid_fkey_relationship.yaml | 7 + .../graphql_query/citus/teardown_citus.yaml | 44 +++- .../subscriptions/basic/teardown_mssql.yaml | 9 +- .../multiplexing/teardown_mssql.yaml | 15 +- server/tests-py/test_graphql_queries.py | 64 +++-- server/tests-py/test_subscriptions.py | 16 +- 23 files changed, 559 insertions(+), 247 deletions(-) create mode 100644 scripts/parse-pytest-backend create mode 100644 server/tests-py/queries/graphql_query/boolexp/basic/setup_invalid_fkey_relationship_mssql.yaml create mode 100644 server/tests-py/queries/graphql_query/citus/setup_invalid_fkey_relationship.yaml diff --git a/scripts/dev.sh b/scripts/dev.sh index fc452ba3cfe..5d736bdc657 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -108,6 +108,7 @@ case "${1-}" in RUN_INTEGRATION_TESTS=true RUN_UNIT_TESTS=false RUN_HLINT=false + source scripts/parse-pytest-backend ;; --hlint) RUN_INTEGRATION_TESTS=false @@ -199,22 +200,49 @@ function citus_start() { citus_wait } -# This is just a faster version of -# mssql_start -# pg_start -# citus_start -function all_dbs_start() { - # start all - mssql_launch_container - MSSQL_RUNNING=1 - pg_launch_container - PG_RUNNING=1 - citus_launch_container - CITUS_RUNNING=1 - # wait for all - pg_wait - mssql_wait - citus_wait +function start_dbs() { + # always launch the postgres container + pg_start + + case "$BACKEND" in + citus) + citus_start + ;; + mssql) + mssql_start + ;; + # bigquery omitted as test setup is atypical. See: + # https://github.com/hasura/graphql-engine-mono/wiki/Testing-BigQuery + esac +} + +function add_sources() { + METADATA_URL=http://127.0.0.1:$HASURA_GRAPHQL_SERVER_PORT/v1/metadata + + # always add a postgres source + echo "" + echo_pretty "Adding Postgres source" + curl "$METADATA_URL" \ + --data-raw '{"type":"pg_add_source","args":{"name":"default","configuration":{"connection_info":{"database_url":"'"$PG_DB_URL"'"}}}}' + + case "$BACKEND" in + # bigquery omitted as test setup is atypical. See: + # https://github.com/hasura/graphql-engine-mono/wiki/Testing-BigQuery + citus) + echo "" + echo_pretty "Adding Citus source" + curl "$METADATA_URL" \ + --data-raw '{"type":"citus_add_source","args":{"name":"citus","configuration":{"connection_info":{"database_url":"'"$CITUS_DB_URL"'"}}}}' + ;; + mssql) + echo "" + echo_pretty "Adding SQL Server source" + curl "$METADATA_URL" \ + --data-raw '{"type":"mssql_add_source","args":{"name":"mssql","configuration":{"connection_info":{"connection_string":"'"$MSSQL_DB_URL"'"}}}}' + ;; + esac + + echo "" } @@ -416,7 +444,7 @@ elif [ "$MODE" = "test" ]; then # rebuilding twice... ugh cabal new-build --project-file=cabal.project.dev-sh exe:graphql-engine test:graphql-engine-tests if [ "$RUN_INTEGRATION_TESTS" = true ]; then - all_dbs_start + start_dbs else # unit tests just need access to a postgres instance: pg_start @@ -467,26 +495,7 @@ elif [ "$MODE" = "test" ]; then echo "" echo " Ok" - METADATA_URL=http://127.0.0.1:$HASURA_GRAPHQL_SERVER_PORT/v1/metadata - - echo "" - echo "Adding Postgres source" - curl "$METADATA_URL" \ - --data-raw '{"type":"pg_add_source","args":{"name":"default","configuration":{"connection_info":{"database_url":"'"$PG_DB_URL"'"}}}}' - - echo "" - echo "Adding SQL Server source" - curl "$METADATA_URL" \ - --data-raw '{"type":"mssql_add_source","args":{"name":"mssql","configuration":{"connection_info":{"connection_string":"'"$MSSQL_DB_URL"'"}}}}' - - echo "" - echo "Adding Citus source" - curl "$METADATA_URL" \ - --data-raw '{"type":"citus_add_source","args":{"name":"citus","configuration":{"connection_info":{"database_url":"'"$CITUS_DB_URL"'"}}}}' - - echo "" - echo "Sources added:" - curl "$METADATA_URL" --data-raw '{"type":"export_metadata","args":{}}' + add_sources cd "$PROJECT_ROOT/server/tests-py" diff --git a/scripts/parse-pytest-backend b/scripts/parse-pytest-backend new file mode 100644 index 00000000000..0f93f0f33b8 --- /dev/null +++ b/scripts/parse-pytest-backend @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +PARAMS="" +BACKEND="postgres" + +die_backends() { +cat <`: for `v2/query` queries such as `_run_sql`. [Example](https://github.com/hasura/graphql-engine/commit/64d52f5fa333f337ef76ada4e0b6abd49353c457/scripts/dev.sh#diff-b34081ef8e1c34492fcf0cf72a8c1d64bcb66944f2ab2efb9ac0812cd7a003c7). 3. `teardown_` and `cleardb_` 4. important: filename suffixes should be the same as the value that’s being passed to `—backend`; that's how the files are looked up. -4. Write test using [the `per_backend_tests` fixture](https://github.com/hasura/graphql-engine/commit/64d52f5fa333f337ef76ada4e0b6abd49353c457/scripts/dev.sh#diff-1034b560ce9984643a4aa4edab1d612aa512f1c3c28bbc93364700620681c962R420), parameterised by backend. [Example](https://github.com/hasura/graphql-engine/commit/64d52f5fa333f337ef76ada4e0b6abd49353c457/scripts/dev.sh#diff-40b7c6ad5362e70cafd29a3ac5d0a5387bd75befad92532ea4aaba99421ba3c8R12-R13). +4. Specify a `backend` parameter for [the `per_backend_tests` fixture](https://github.com/hasura/graphql-engine/commit/64d52f5fa333f337ef76ada4e0b6abd49353c457/scripts/dev.sh#diff-1034b560ce9984643a4aa4edab1d612aa512f1c3c28bbc93364700620681c962R420), parameterised by backend. [Example](https://github.com/hasura/graphql-engine/commit/64d52f5fa333f337ef76ada4e0b6abd49353c457/scripts/dev.sh#diff-40b7c6ad5362e70cafd29a3ac5d0a5387bd75befad92532ea4aaba99421ba3c8R12-R13). 5. Optional: Run the existing (Postgres) test suite against the new backend to identify and group common and backend-specific tests into their own classes. Tests against alternative backends aren't yet run/supported in CI, so please test locally. diff --git a/server/tests-py/conftest.py b/server/tests-py/conftest.py index 7a104b1d033..3c5a7a6b4e1 100644 --- a/server/tests-py/conftest.py +++ b/server/tests-py/conftest.py @@ -311,9 +311,10 @@ def evts_webhook(request): @pytest.fixture(scope='module') def actions_fixture(hge_ctx): - pg_version = hge_ctx.pg_version - if pg_version < 100000: # version less than 10.0 - pytest.skip('Actions are not supported on Postgres version < 10') + if hge_ctx.is_default_backend: + pg_version = hge_ctx.pg_version + if pg_version < 100000: # version less than 10.0 + pytest.skip('Actions are not supported on Postgres version < 10') # Start actions' webhook server webhook_httpd = ActionsWebhookServer(hge_ctx, server_address=('127.0.0.1', 5593)) @@ -433,6 +434,11 @@ def per_method_db_data_for_mutation_tests(request, hge_ctx, per_class_db_schema_ ) @pytest.fixture(scope='function') +def backend(): + "This fixture provides a default `backend` value for the `per_backend_tests` fixture" + return 'postgres' + +@pytest.fixture(scope='function', autouse=True) def per_backend_tests(hge_ctx, backend): """ This fixture ignores backend-specific tests unless the relevant --backend flag has been passed. @@ -454,15 +460,19 @@ def db_state_context(request, hge_ctx): for filename in ['setup', 'teardown', 'schema_setup', 'schema_teardown'] ] - if hge_ctx.backend == 'postgres': + # only lookup files relevant to the tests being run. + # defaults to postgres file lookup + check_file_exists = hge_ctx.backend == backend + + if hge_ctx.is_default_backend: db_context = db_context_with_schema_common( request, hge_ctx, 'setup_files', 'setup.yaml', 'teardown_files', - 'teardown.yaml', True + 'teardown.yaml', check_file_exists ) else: db_context = db_context_with_schema_common_new ( request, hge_ctx, 'setup_files', setup, 'teardown_files', - teardown, schema_setup, schema_teardown, True + teardown, schema_setup, schema_teardown, check_file_exists ) yield from db_context diff --git a/server/tests-py/context.py b/server/tests-py/context.py index d6d59066b8c..9919267039b 100644 --- a/server/tests-py/context.py +++ b/server/tests-py/context.py @@ -500,12 +500,14 @@ class HGECtx: self.ws_client_relay = GQLWsClient(self, '/v1beta1/relay') self.backend = config.getoption('--backend') + self.default_backend = 'postgres' + self.is_default_backend = self.backend == self.default_backend # HGE version result = subprocess.run(['../../scripts/get-version.sh'], shell=False, stdout=subprocess.PIPE, check=True) env_version = os.getenv('VERSION') self.version = env_version if env_version else result.stdout.decode('utf-8').strip() - if not self.metadata_disabled and not config.getoption('--skip-schema-setup'): + if self.is_default_backend and not self.metadata_disabled and not config.getoption('--skip-schema-setup'): try: st_code, resp = self.v2q_f("queries/" + self.backend_suffix("clear_db")+ ".yaml") except requests.exceptions.RequestException as e: @@ -514,7 +516,7 @@ class HGECtx: assert st_code == 200, resp # Postgres version - if self.backend == 'postgres': + if self.is_default_backend: pg_version_text = self.sql('show server_version_num').fetchone()['server_version_num'] self.pg_version = int(pg_version_text) @@ -602,7 +604,7 @@ class HGECtx: return self.v2q(yml.load(f)) def backend_suffix(self, filename): - if self.backend == 'postgres': + if self.is_default_backend: return filename else: return filename + "_" + self.backend diff --git a/server/tests-py/queries/explain/setup_mssql.yaml b/server/tests-py/queries/explain/setup_mssql.yaml index a74f9e0faed..aa5a6e9ed7c 100644 --- a/server/tests-py/queries/explain/setup_mssql.yaml +++ b/server/tests-py/queries/explain/setup_mssql.yaml @@ -6,6 +6,7 @@ args: source: mssql table: name: user + - type: mssql_create_select_permission args: source: mssql diff --git a/server/tests-py/queries/explain/teardown_mssql.yaml b/server/tests-py/queries/explain/teardown_mssql.yaml index 54fdb9f6898..a711c818648 100644 --- a/server/tests-py/queries/explain/teardown_mssql.yaml +++ b/server/tests-py/queries/explain/teardown_mssql.yaml @@ -1,2 +1,8 @@ type: bulk -args: [] +args: + - type: mssql_untrack_table + args: + source: mssql + table: + name: user + cascade: true diff --git a/server/tests-py/queries/graphql_query/basic/schema_teardown_mssql.yaml b/server/tests-py/queries/graphql_query/basic/schema_teardown_mssql.yaml index 555e0cc2b93..db1b49c56eb 100644 --- a/server/tests-py/queries/graphql_query/basic/schema_teardown_mssql.yaml +++ b/server/tests-py/queries/graphql_query/basic/schema_teardown_mssql.yaml @@ -9,5 +9,6 @@ args: drop table article; drop table author; drop table [user]; - drop table article_multi; - drop table author_multi; + -- TODO: https://github.com/hasura/graphql-engine-mono/issues/1435 + -- drop table article_multi; + -- drop table author_multi; diff --git a/server/tests-py/queries/graphql_query/basic/setup_citus.yaml b/server/tests-py/queries/graphql_query/basic/setup_citus.yaml index 9548ea04c5a..cee14312f25 100644 --- a/server/tests-py/queries/graphql_query/basic/setup_citus.yaml +++ b/server/tests-py/queries/graphql_query/basic/setup_citus.yaml @@ -1,28 +1,25 @@ type: bulk args: -#Test types table +# track tables - type: citus_track_table args: source: citus table: name: test_types -#Author table - type: citus_track_table args: source: citus table: name: author -#Article table - type: citus_track_table args: source: citus table: name: article -#User table - type: citus_track_table args: source: citus diff --git a/server/tests-py/queries/graphql_query/basic/setup_mssql.yaml b/server/tests-py/queries/graphql_query/basic/setup_mssql.yaml index 688efa2406e..676d10bdde9 100644 --- a/server/tests-py/queries/graphql_query/basic/setup_mssql.yaml +++ b/server/tests-py/queries/graphql_query/basic/setup_mssql.yaml @@ -1,35 +1,31 @@ type: bulk args: -#Types table +# track tables - type: mssql_track_table args: source: mssql table: name: test_types -#Author table - type: mssql_track_table args: source: mssql table: name: author -#Article table - type: mssql_track_table args: source: mssql table: name: article -#User table - type: mssql_track_table args: source: mssql table: name: user -#Person table - type: mssql_track_table args: source: mssql @@ -48,7 +44,7 @@ args: table: name: author_multi -#Object relationship +# create relationships - type: mssql_create_object_relationship args: source: mssql @@ -57,7 +53,6 @@ args: using: foreign_key_constraint_on: author_id -#Object relationship - type: mssql_create_object_relationship args: source: mssql @@ -66,7 +61,6 @@ args: using: foreign_key_constraint_on: co_author_id -#Array relationship - type: mssql_create_array_relationship args: source: mssql @@ -78,7 +72,6 @@ args: column: author_id -#Array relationship - type: mssql_create_array_relationship args: source: mssql @@ -89,7 +82,6 @@ args: table: article column: co_author_id -#Object relationship - type: mssql_create_object_relationship args: source: mssql @@ -98,7 +90,6 @@ args: using: foreign_key_constraint_on: ["author_id1", "author_id2"] -#Array relationship - type: mssql_create_array_relationship args: source: mssql diff --git a/server/tests-py/queries/graphql_query/basic/teardown_citus.yaml b/server/tests-py/queries/graphql_query/basic/teardown_citus.yaml index 54fdb9f6898..bd5a1cfff9f 100644 --- a/server/tests-py/queries/graphql_query/basic/teardown_citus.yaml +++ b/server/tests-py/queries/graphql_query/basic/teardown_citus.yaml @@ -1,2 +1,54 @@ type: bulk -args: [] +args: + +# untrack tables +- type: citus_untrack_table + args: + source: citus + table: + name: test_types + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: author + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: article + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: user + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: person + cascade: true + +- type: citus_untrack_table + args: + source: citus + schema: public + table: + name: author_multi + cascade: true + +- type: citus_untrack_table + args: + source: citus + schema: public + table: + name: article_multi + cascade: true diff --git a/server/tests-py/queries/graphql_query/basic/teardown_mssql.yaml b/server/tests-py/queries/graphql_query/basic/teardown_mssql.yaml index 930903fff66..28f4e43e59a 100644 --- a/server/tests-py/queries/graphql_query/basic/teardown_mssql.yaml +++ b/server/tests-py/queries/graphql_query/basic/teardown_mssql.yaml @@ -1,44 +1,52 @@ type: bulk args: -#Object relationship -- type: mssql_drop_relationship +# untrack tables +- type: mssql_untrack_table args: source: mssql - table: article - relationship: author + table: + name: test_types + cascade: true -#Array relationship -- type: mssql_drop_relationship +- type: mssql_untrack_table args: source: mssql - table: author - relationship: articles + table: + name: author + cascade: true -#Object relationship -- type: mssql_drop_relationship +- type: mssql_untrack_table args: source: mssql - table: article - relationship: co_author + table: + name: article + cascade: true -#Array relationship -- type: mssql_drop_relationship +- type: mssql_untrack_table args: source: mssql - table: author - relationship: co_articles + table: + name: user + cascade: true -#Object relationship -- type: mssql_drop_relationship +- type: mssql_untrack_table args: source: mssql - table: article_multi - relationship: author + table: + name: person + cascade: true -#Array relationship -- type: mssql_drop_relationship +- type: mssql_untrack_table args: source: mssql - table: author_multi - relationship: articles + table: + name: article_multi + cascade: true + +- type: mssql_untrack_table + args: + source: mssql + table: + name: author_multi + cascade: true diff --git a/server/tests-py/queries/graphql_query/boolexp/basic/setup_invalid_fkey_relationship_mssql.yaml b/server/tests-py/queries/graphql_query/boolexp/basic/setup_invalid_fkey_relationship_mssql.yaml new file mode 100644 index 00000000000..d27127a2d54 --- /dev/null +++ b/server/tests-py/queries/graphql_query/boolexp/basic/setup_invalid_fkey_relationship_mssql.yaml @@ -0,0 +1,7 @@ +type: mssql_create_array_relationship +args: + source: mssql + table: author_multi + name: articles + using: + foreign_key_constraint_on: "I should have been an object" diff --git a/server/tests-py/queries/graphql_query/boolexp/basic/setup_mssql.yaml b/server/tests-py/queries/graphql_query/boolexp/basic/setup_mssql.yaml index 6bf408bcac0..06db2ebb104 100644 --- a/server/tests-py/queries/graphql_query/boolexp/basic/setup_mssql.yaml +++ b/server/tests-py/queries/graphql_query/boolexp/basic/setup_mssql.yaml @@ -1,126 +1,120 @@ type: bulk args: + - type: mssql_track_table + args: + source: mssql + table: + name: author -# Track tables -- type: mssql_track_table - args: - source: mssql - table: + - type: mssql_track_table + args: + source: mssql + table: + name: article + + - type: mssql_track_table + args: + source: mssql + table: + name: city + + - type: mssql_track_table + args: + source: mssql + table: + name: orders + + - type: mssql_track_table + args: + source: mssql + table: + name: message + + - type: mssql_track_table + args: + source: mssql + table: + name: uuid_test + + - type: mssql_track_table + args: + source: mssql + table: + name: user + + - type: mssql_track_table + args: + source: mssql + table: + name: account + + - type: mssql_track_table + args: + source: mssql + table: + name: table_with_sql_identifier + + #Object relationships + - type: mssql_create_object_relationship + args: + source: mssql + table: article name: author + using: + foreign_key_constraint_on: author_id -- type: mssql_track_table - args: - source: mssql - table: - name: article + - type: mssql_create_object_relationship + args: + source: mssql + table: message + name: parent + using: + foreign_key_constraint_on: parent_id + + #Array relationships + - type: mssql_create_array_relationship + args: + source: mssql + table: author + name: articles + using: + foreign_key_constraint_on: + table: article + column: author_id + + - type: mssql_create_array_relationship + args: + source: mssql + table: message + name: children + using: + foreign_key_constraint_on: + table: message + column: parent_id -- type: mssql_track_table - args: - source: mssql - table: - name: city + - type: mssql_create_select_permission + args: + source: mssql + table: article + role: user + permission: + columns: + - author_id + - content + - id + - title + filter: + is_published: + _eq: 1 -- type: mssql_track_table - args: - source: mssql - table: - name: orders - -- type: mssql_track_table - args: - source: mssql - table: - name: message - - -- type: mssql_track_table - args: - source: mssql - table: - name: uuid_test - - -- type: mssql_track_table - args: - source: mssql - table: - name: user - - -- type: mssql_track_table - args: - source: mssql - table: - name: account - - -- type: mssql_track_table - args: - source: mssql - table: - name: table_with_sql_identifier - -#Object relationships -- type: mssql_create_object_relationship - args: - source: mssql - table: article - name: author - using: - foreign_key_constraint_on: author_id - -- type: mssql_create_object_relationship - args: - source: mssql - table: message - name: parent - using: - foreign_key_constraint_on: parent_id - -#Array relationships -- type: mssql_create_array_relationship - args: - source: mssql - table: author - name: articles - using: - foreign_key_constraint_on: - table: article - column: author_id - -- type: mssql_create_array_relationship - args: - source: mssql - table: message - name: children - using: - foreign_key_constraint_on: - table: message - column: parent_id - -- type: mssql_create_select_permission - args: - source: mssql - table: article - role: user - permission: - columns: - - author_id - - content - - id - - title - filter: - is_published: - _eq: 1 - -- type: mssql_create_select_permission - args: - source: mssql - table: author - role: user - permission: - columns: - - id - - name - filter: {} + - type: mssql_create_select_permission + args: + source: mssql + table: author + role: user + permission: + columns: + - id + - name + filter: {} diff --git a/server/tests-py/queries/graphql_query/boolexp/basic/teardown_mssql.yaml b/server/tests-py/queries/graphql_query/boolexp/basic/teardown_mssql.yaml index 54fdb9f6898..57554387d2d 100644 --- a/server/tests-py/queries/graphql_query/boolexp/basic/teardown_mssql.yaml +++ b/server/tests-py/queries/graphql_query/boolexp/basic/teardown_mssql.yaml @@ -1,2 +1,64 @@ type: bulk -args: [] +args: + - type: mssql_untrack_table + args: + source: mssql + table: + name: author + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: article + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: city + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: orders + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: message + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: uuid_test + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: user + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: account + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: table_with_sql_identifier + cascade: true diff --git a/server/tests-py/queries/graphql_query/boolexp/search/teardown_mssql.yaml b/server/tests-py/queries/graphql_query/boolexp/search/teardown_mssql.yaml index 9f423bdd95e..569ccd53d09 100644 --- a/server/tests-py/queries/graphql_query/boolexp/search/teardown_mssql.yaml +++ b/server/tests-py/queries/graphql_query/boolexp/search/teardown_mssql.yaml @@ -1,8 +1,22 @@ type: bulk args: - #Drop relationship first - - type: mssql_drop_relationship - args: - source: mssql - table: author - relationship: articles +- type: mssql_untrack_table + args: + source: mssql + table: + name: author + cascade: true + +- type: mssql_untrack_table + args: + source: mssql + table: + name: article + cascade: true + +- type: mssql_untrack_table + args: + source: mssql + table: + name: city + cascade: true diff --git a/server/tests-py/queries/graphql_query/boolexp/spatial/teardown_mssql.yaml b/server/tests-py/queries/graphql_query/boolexp/spatial/teardown_mssql.yaml index 54fdb9f6898..c3ec30bcbbe 100644 --- a/server/tests-py/queries/graphql_query/boolexp/spatial/teardown_mssql.yaml +++ b/server/tests-py/queries/graphql_query/boolexp/spatial/teardown_mssql.yaml @@ -1,2 +1,16 @@ type: bulk -args: [] +args: + +- type: mssql_untrack_table + args: + source: mssql + table: + name: spatial_types_geom + cascade: true + +- type: mssql_untrack_table + args: + source: mssql + table: + name: spatial_types_geog + cascade: true diff --git a/server/tests-py/queries/graphql_query/citus/setup_invalid_fkey_relationship.yaml b/server/tests-py/queries/graphql_query/citus/setup_invalid_fkey_relationship.yaml new file mode 100644 index 00000000000..a753ac24101 --- /dev/null +++ b/server/tests-py/queries/graphql_query/citus/setup_invalid_fkey_relationship.yaml @@ -0,0 +1,7 @@ +type: citus_create_array_relationship +args: + source: citus + table: author_multi + name: articles + using: + foreign_key_constraint_on: "I should have been an object" diff --git a/server/tests-py/queries/graphql_query/citus/teardown_citus.yaml b/server/tests-py/queries/graphql_query/citus/teardown_citus.yaml index 54fdb9f6898..e4ba911ec2a 100644 --- a/server/tests-py/queries/graphql_query/citus/teardown_citus.yaml +++ b/server/tests-py/queries/graphql_query/citus/teardown_citus.yaml @@ -1,2 +1,44 @@ type: bulk -args: [] +args: + +- type: citus_untrack_table + args: + source: citus + table: + name: author + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: article + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: country + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: state + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: disaster + cascade: true + +- type: citus_untrack_table + args: + source: citus + table: + name: disaster_affected_state + cascade: true diff --git a/server/tests-py/queries/subscriptions/basic/teardown_mssql.yaml b/server/tests-py/queries/subscriptions/basic/teardown_mssql.yaml index 54fdb9f6898..29db7610b31 100644 --- a/server/tests-py/queries/subscriptions/basic/teardown_mssql.yaml +++ b/server/tests-py/queries/subscriptions/basic/teardown_mssql.yaml @@ -1,2 +1,9 @@ type: bulk -args: [] +args: + +- type: mssql_untrack_table + args: + source: mssql + table: + schema: hge_tests + name: test_t1 diff --git a/server/tests-py/queries/subscriptions/multiplexing/teardown_mssql.yaml b/server/tests-py/queries/subscriptions/multiplexing/teardown_mssql.yaml index 54fdb9f6898..abf9a0ff793 100644 --- a/server/tests-py/queries/subscriptions/multiplexing/teardown_mssql.yaml +++ b/server/tests-py/queries/subscriptions/multiplexing/teardown_mssql.yaml @@ -1,2 +1,15 @@ type: bulk -args: [] +args: + - type: mssql_untrack_table + args: + source: mssql + table: + name: test + cascade: true + + - type: mssql_untrack_table + args: + source: mssql + table: + name: articles + cascade: true diff --git a/server/tests-py/test_graphql_queries.py b/server/tests-py/test_graphql_queries.py index f5b7448ba86..534e53637a4 100644 --- a/server/tests-py/test_graphql_queries.py +++ b/server/tests-py/test_graphql_queries.py @@ -10,7 +10,7 @@ usefixtures = pytest.mark.usefixtures @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['bigquery']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBasicBigquery: # initialize the metadata @@ -106,7 +106,7 @@ class TestGraphQLQueryBasicBigquery: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['citus', 'mssql', 'postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBasicCommon: # This also exercises support for multiple operations in a document: def test_select_query_author(self, hge_ctx, transport): @@ -154,10 +154,6 @@ class TestGraphQLQueryBasicCommon: def test_select_query_multiple_columns_obj_fkey(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + "/select_multiple_columns_obj_fkey.yaml", transport) - def test_create_invalid_fkey_relationship(self, hge_ctx, transport): - st_code, resp = hge_ctx.v1q_f(self.dir() + '/setup_invalid_fkey_relationship.yaml') - assert st_code == 400, resp - assert resp['error'] == "Expecting object { table, columns }." @classmethod def dir(cls): @@ -165,7 +161,7 @@ class TestGraphQLQueryBasicCommon: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['mssql']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBasicMSSQL: def test_select_various_mssql_types(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + '/select_query_test_types_mssql.yaml', transport) @@ -182,7 +178,7 @@ class TestGraphQLQueryBasicMSSQL: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBasicPostgres: # Can't run server upgrade tests, as this test has a schema change @pytest.mark.skip_server_upgrade_test @@ -224,13 +220,18 @@ class TestGraphQLQueryBasicPostgres: transport = 'http' check_query_f(hge_ctx, self.dir() + "/select_query_batching_with_one_error.yaml", transport) + def test_create_invalid_fkey_relationship(self, hge_ctx, transport): + st_code, resp = hge_ctx.v1q_f(self.dir() + '/setup_invalid_fkey_relationship.yaml') + assert st_code == 400, resp + assert resp['error'] == "Expecting object { table, columns }." + @classmethod def dir(cls): return 'queries/graphql_query/basic' @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['citus']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBasicCitus: def test_nested_select_with_foreign_key_alter(self, hge_ctx, transport): transport = 'http' @@ -257,13 +258,18 @@ class TestGraphQLQueryBasicCitus: transport = 'http' check_query_f(hge_ctx, self.dir() + "/select_query_disaster_functions.yaml", transport) + def test_create_invalid_fkey_relationship(self, hge_ctx, transport): + st_code, resp = hge_ctx.v1metadataq_f(self.dir() + '/setup_invalid_fkey_relationship.yaml') + assert st_code == 400, resp + assert resp['error'] == "Expecting object { table, columns }." + @classmethod def dir(cls): return 'queries/graphql_query/citus' @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['citus', 'postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryFragments: def test_select_query_top_level_fragment(self, hge_ctx, transport): @@ -382,10 +388,12 @@ class TestGraphQLQueryOffsets: def dir(cls): return 'queries/graphql_query/offset' - -@pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription']) +# FIXME: MSSQL subscriptions multiplexing regression +# https://github.com/hasura/graphql-engine-mono/issues/1434 +# @pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription']) +@pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['mssql', 'postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBoolExpBasicCommon: def test_order_delivered_at_is_null(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + '/select_query_order_delivered_at_is_null.yaml', transport) @@ -432,7 +440,7 @@ class TestGraphQLQueryBoolExpBasicCommon: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBoolExpBasicPostgres: def test_author_article_operator_ne_not_found_err(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + '/select_author_article_operator_ne_not_found_err_postgres.yaml', transport) @@ -467,7 +475,7 @@ class TestGraphQLQueryBoolExpBasicPostgres: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['mssql']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBoolExpBasicMSSQL: def test_author_article_operator_ne_not_found_err(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + '/select_author_article_operator_ne_not_found_err_mssql.yaml', transport) @@ -478,9 +486,15 @@ class TestGraphQLQueryBoolExpBasicMSSQL: def test_uuid_test_in_uuid_col(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + '/select_uuid_test_in_uuid_col_mssql.yaml', transport) + @pytest.mark.skip(reason="TODO: https://github.com/hasura/graphql-engine-mono/issues/1438") def test_bools(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + '/select_bools_mssql.yaml', transport) + def test_create_invalid_fkey_relationship(self, hge_ctx, transport): + st_code, resp = hge_ctx.v1metadataq_f(self.dir() + '/setup_invalid_fkey_relationship_mssql.yaml') + assert st_code == 400, resp + assert resp['error'] == "Expecting object { table, columns }." + @classmethod def dir(cls): return 'queries/graphql_query/boolexp/basic' @@ -574,9 +588,12 @@ class TestGraphQLInheritedRoles: check_query_f(hge_ctx, self.dir() + '/inherited_role_with_some_roles_having_no_permissions.yaml') -@pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription']) +# FIXME: MSSQL subscriptions multiplexing regression +# https://github.com/hasura/graphql-engine-mono/issues/1434 +# @pytest.mark.parametrize("transport", ['http', 'websocket', 'subscription']) +@pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['postgres', 'mssql']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBoolExpSearchCommon: def test_city_where_like(self, hge_ctx, transport): @@ -591,7 +608,7 @@ class TestGraphQLQueryBoolExpSearchCommon: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBoolExpSearchPostgres: def test_city_where_ilike(self, hge_ctx, transport): @@ -627,7 +644,7 @@ class TestGraphQLQueryBoolExpSearchPostgres: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['mssql']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBoolExpSearchMSSQL: def test_city_where_like(self, hge_ctx, transport): @@ -932,8 +949,11 @@ class TestUnauthorizedRolePermission: def test_unauth_role(self, hge_ctx, transport): check_query_f(hge_ctx, self.dir() + '/unauthorized_role.yaml', transport, False) -@pytest.mark.parametrize("backend", ['postgres', 'mssql']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +# FIXME: MSSQL subscriptions multiplexing regression +# https://github.com/hasura/graphql-engine-mono/issues/1434 +# @pytest.mark.parametrize("backend", ['postgres', 'mssql']) +@pytest.mark.parametrize("backend", ['postgres']) +@usefixtures('per_class_tests_db_state') class TestGraphQLExplain: @classmethod def dir(cls): @@ -1113,7 +1133,7 @@ class TestGraphQLQueryBoolExpLtree: @pytest.mark.parametrize("transport", ['http', 'websocket']) @pytest.mark.parametrize("backend", ['mssql']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +@usefixtures('per_class_tests_db_state') class TestGraphQLQueryBoolExpSpatialMSSQL: @pytest.mark.skip_server_upgrade_test def test_select_spatial_mssql_types(self, hge_ctx, transport): diff --git a/server/tests-py/test_subscriptions.py b/server/tests-py/test_subscriptions.py index e4f78d30353..cf458d80280 100644 --- a/server/tests-py/test_subscriptions.py +++ b/server/tests-py/test_subscriptions.py @@ -66,7 +66,7 @@ class TestSubscriptionCtrl(object): ev = ws_client.get_ws_event(3) @pytest.mark.parametrize("backend", ['mssql', 'postgres']) -@usefixtures('per_class_tests_db_state', 'ws_conn_init', 'per_backend_tests') +@usefixtures('per_class_tests_db_state', 'ws_conn_init') class TestSubscriptionBasic: @classmethod def dir(cls): @@ -251,8 +251,11 @@ class TestSubscriptionLiveQueries: with pytest.raises(queue.Empty): ev = ws_client.get_ws_event(3) -@pytest.mark.parametrize("backend", ['mssql', 'postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests') +# FIXME: MSSQL subscriptions multiplexing regression +# https://github.com/hasura/graphql-engine-mono/issues/1434 +# @pytest.mark.parametrize("backend", ['mssql', 'postgres']) +@pytest.mark.parametrize("backend", ['postgres']) +@usefixtures('per_class_tests_db_state') class TestSubscriptionMultiplexing: @classmethod @@ -316,8 +319,11 @@ class TestSubscriptionMultiplexing: return sql -@pytest.mark.parametrize("backend", ['mssql', 'postgres']) -@usefixtures('per_class_tests_db_state', 'per_backend_tests', 'ws_conn_init') +# FIXME: MSSQL subscriptions multiplexing regression +# https://github.com/hasura/graphql-engine-mono/issues/1434 +# @pytest.mark.parametrize("backend", ['mssql', 'postgres']) +@pytest.mark.parametrize("backend", ['postgres']) +@usefixtures('per_class_tests_db_state', 'ws_conn_init') class TestSubscriptionUDFWithSessionArg: """ Test a user-defined function which uses the entire session variables as argument