From 4175b5339531186c171ed5fee1d78158359039fa Mon Sep 17 00:00:00 2001 From: Samir Talwar Date: Mon, 16 Jan 2023 17:42:45 +0100 Subject: [PATCH] server/api-tests: Add a Docker Compose file for the API tests. We were previously using the Docker Compose file in the root directory for manual testing _and_ the server API tests. This splits them so we can e.g. add Yugabyte for easy manual testing. In the future, this will also allow us to use ephemeral ports for API test databases, while keeping the fixed ports for manual testing. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/7524 GitOrigin-RevId: 7244e296b0ed0ace9782b6f44f321933a9d9a49d --- docker-compose.yaml | 2 + docker-compose/databases.yaml | 1 - scripts/make/test-infrastructure.mk | 11 ++-- scripts/make/tests.mk | 16 ++--- server/lib/api-tests/README.md | 8 +-- server/lib/api-tests/docker-compose.yaml | 78 ++++++++++++++++++++++++ server/tests-py/docker-compose.yml | 2 + server/tests-py/docker/postgres-init.sh | 0 8 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 server/lib/api-tests/docker-compose.yaml mode change 100644 => 100755 server/tests-py/docker/postgres-init.sh diff --git a/docker-compose.yaml b/docker-compose.yaml index 565e2cd0164..1469a25047c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -29,6 +29,8 @@ version: "3.6" +name: hge-manual-tests + services: mariadb: extends: diff --git a/docker-compose/databases.yaml b/docker-compose/databases.yaml index bbfd40d549d..2d0894797b3 100644 --- a/docker-compose/databases.yaml +++ b/docker-compose/databases.yaml @@ -69,7 +69,6 @@ services: cockroach: image: cockroachdb/cockroach:latest-v22.2 - platform: linux/amd64 command: - start-single-node - --insecure diff --git a/scripts/make/test-infrastructure.mk b/scripts/make/test-infrastructure.mk index d665d5e9afb..01db6da83e5 100644 --- a/scripts/make/test-infrastructure.mk +++ b/scripts/make/test-infrastructure.mk @@ -1,3 +1,6 @@ +API_TESTS_DOCKER_COMPOSE = docker compose --project-directory=./server/lib/api-tests +PYTHON_TESTS_DOCKER_COMPOSE = docker compose --project-directory=./server/tests-py + # Use the Azure SQL Edge image instead of the SQL Server image on arm64. # The latter doesn't work yet. ifeq ($(shell uname -m),arm64) @@ -25,18 +28,18 @@ endef .PHONY: build-backends ## build-backends: build Docker images for any backends that need them build-backends: - docker compose build + $(API_TESTS_DOCKER_COMPOSE) build .PHONY: start-backends ## start-backends: start all known backends in Docker and wait for them to be ready start-backends: build-backends - docker compose up --detach --wait + $(API_TESTS_DOCKER_COMPOSE) up --detach --wait .PHONY: stop-everything ## stop-everything: tear down test databases stop-everything: - docker compose down --volumes - cd server/tests-py && docker compose down --volumes + $(API_TESTS_DOCKER_COMPOSE) down --volumes + $(PYTHON_TESTS_DOCKER_COMPOSE) down --volumes .PHONY: remove-tix-file remove-tix-file: diff --git a/scripts/make/tests.mk b/scripts/make/tests.mk index 94e4ca39d91..783fbcd9627 100644 --- a/scripts/make/tests.mk +++ b/scripts/make/tests.mk @@ -5,7 +5,7 @@ GRAPHQL_ENGINE_PRO_PATH=$(shell cabal list-bin exe:graphql-engine-pro) ## test-bigquery: run tests for BigQuery backend # will require some setup detailed here: https://github.com/hasura/graphql-engine-mono/tree/main/server/lib/api-tests#required-setup-for-bigquery-tests test-bigquery: build remove-tix-file - docker compose up -d --wait postgres + $(API_TESTS_DOCKER_COMPOSE) up -d --wait postgres $(call stop_after, \ HASURA_TEST_BACKEND_TYPE=BigQuery \ GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \ @@ -14,7 +14,7 @@ test-bigquery: build remove-tix-file .PHONY: test-sqlserver ## test-sqlserver: run tests for MS SQL Server backend test-sqlserver: build remove-tix-file - docker compose up -d --wait postgres sqlserver-healthcheck + $(API_TESTS_DOCKER_COMPOSE) up -d --wait postgres sqlserver-healthcheck $(call stop_after, \ HASURA_TEST_BACKEND_TYPE=SQLServer \ GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \ @@ -23,7 +23,7 @@ test-sqlserver: build remove-tix-file .PHONY: test-citus ## test-citus: run tests for Citus backend test-citus: build remove-tix-file - docker compose up -d --wait postgres citus + $(API_TESTS_DOCKER_COMPOSE) up -d --wait postgres citus $(call stop_after, \ HASURA_TEST_BACKEND_TYPE=Citus \ GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \ @@ -32,8 +32,8 @@ test-citus: build remove-tix-file .PHONY: test-data-connectors ## test-data-connectors: run tests for Data Connectors test-data-connectors: build remove-tix-file - docker compose build - docker compose up -d --wait postgres dc-reference-agent dc-sqlite-agent + $(API_TESTS_DOCKER_COMPOSE) build + $(API_TESTS_DOCKER_COMPOSE) up -d --wait postgres dc-reference-agent dc-sqlite-agent $(call stop_after, \ HASURA_TEST_BACKEND_TYPE=DataConnector \ GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \ @@ -42,7 +42,7 @@ test-data-connectors: build remove-tix-file .PHONY: test-cockroach ## test-cockroach: run tests for Cockroach backend test-cockroach: build remove-tix-file - docker compose up -d --wait postgres cockroach + $(API_TESTS_DOCKER_COMPOSE) up -d --wait postgres cockroach $(call stop_after, \ HASURA_TEST_BACKEND_TYPE=Cockroach \ GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \ @@ -53,7 +53,7 @@ test-cockroach: build remove-tix-file # we have a few tests labeled with 'Postgres' which test their variants, too, # so this also starts containers for Postgres variants test-postgres: build remove-tix-file - docker compose up -d --wait postgres cockroach citus dc-sqlite-agent + $(API_TESTS_DOCKER_COMPOSE) up -d --wait postgres cockroach citus dc-sqlite-agent $(call stop_after, \ HASURA_TEST_BACKEND_TYPE=Postgres \ GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \ @@ -79,7 +79,7 @@ test-backends: build start-backends remove-tix-file .PHONY: test-matrix ## test-matrix: postgres test matrix generator test-matrix: build remove-tix-file - docker compose up -d --wait postgres cockroach citus dc-sqlite-agent + $(API_TESTS_DOCKER_COMPOSE) up -d --wait postgres cockroach citus dc-sqlite-agent $(call stop_after, \ GRAPHQL_ENGINE=$(GRAPHQL_ENGINE_PATH) \ cabal run api-tests:exe:produce-feature-matrix +RTS -N4 -RTS) diff --git a/server/lib/api-tests/README.md b/server/lib/api-tests/README.md index 4fad25549ef..a41ffbe5369 100644 --- a/server/lib/api-tests/README.md +++ b/server/lib/api-tests/README.md @@ -9,7 +9,7 @@ RFC](../../../rfcs/hspec-test-suite.md). Most of the required setup concerns (and is documented in the README for) [../test-harness/README.md](the test harness), so please follow that link for -more information. +more information. The tests need to know the location of the `graphql-engine` executable: @@ -26,11 +26,11 @@ $ export HASURA_BIGQUERY_PROJECT_ID=??? # The project ID $ export HASURA_BIGQUERY_SERVICE_KEY=??? # The service account key ``` -After that, BigQuery will be ready to test. +After that, BigQuery will be ready to test. +For everything else, run the following in this directory: -For everything else, run the following in the root of `graphql-engine`: -``` +```bash $ docker-compose up ``` diff --git a/server/lib/api-tests/docker-compose.yaml b/server/lib/api-tests/docker-compose.yaml new file mode 100644 index 00000000000..70aff4d8c51 --- /dev/null +++ b/server/lib/api-tests/docker-compose.yaml @@ -0,0 +1,78 @@ +version: "3.6" + +name: hge-api-tests + +services: + postgres: + extends: + file: ../../../docker-compose/databases.yaml + service: postgres + ports: + - "65002:5432" + environment: + POSTGRES_USER: "hasura" + POSTGRES_PASSWORD: "hasura" + POSTGRES_DB: "hasura" + volumes: + - postgres-data:/var/lib/postgresql/data + - ../../../docker-compose/postgres/init.sh:/docker-entrypoint-initdb.d/init-hasura.sh:ro + + citus: + extends: + file: ../../../docker-compose/databases.yaml + service: citus + ports: + - "65004:5432" + environment: + POSTGRES_USER: "hasura" + POSTGRES_PASSWORD: "hasura" + POSTGRES_DB: "hasura" + volumes: + - citus-data:/var/lib/postgresql/data + - ../../../docker-compose/postgres/init.sh:/docker-entrypoint-initdb.d/init-hasura.sh:ro + + cockroach: + extends: + file: ../../../docker-compose/databases.yaml + service: cockroach + ports: + - "65008:26257" + environment: + COCKROACH_USER: "root" + COCKROACH_DATABASE: "hasura" + volumes: + - cockroach-data:/cockroach/cockroach-data + + sqlserver: + extends: + file: ../../../docker-compose/databases.yaml + service: sqlserver + ports: + - "65003:1433" + volumes: + - mssql-data:/var/opt/mssql + + sqlserver-healthcheck: + extends: + file: ../../../docker-compose/databases.yaml + service: sqlserver-healthcheck + depends_on: + sqlserver: + condition: service_started + + dc-reference-agent: + extends: + file: ../../../dc-agents/docker-compose.yaml + service: dc-reference-agent + + dc-sqlite-agent: + extends: + file: ../../../dc-agents/docker-compose.yaml + service: dc-sqlite-agent + +volumes: + citus-data: + cockroach-data: + mariadb-data: + mssql-data: + postgres-data: diff --git a/server/tests-py/docker-compose.yml b/server/tests-py/docker-compose.yml index af373a8cdec..b21e8dd0949 100644 --- a/server/tests-py/docker-compose.yml +++ b/server/tests-py/docker-compose.yml @@ -2,6 +2,8 @@ version: "3.6" +name: hge-python-tests + services: cabal-update: image: hasura/graphql-engine-server-builder:${DOCKER_PLATFORM:-}-${HASURA_GRAPHQL_ENGINE_SERVER_BUILDER_SHA} diff --git a/server/tests-py/docker/postgres-init.sh b/server/tests-py/docker/postgres-init.sh old mode 100644 new mode 100755