server: Get make test-backends working and somewhat speedy.

* Fix `make start-sqlserver` so it can find `sqlcmd`.
* Start the DC reference agent when testing all backends.
* Start backends in parallel so it doesn't take so long to spin them up. This is achieved by splitting all `start-*` tasks into `spawn-*` and `wait-for-*`.

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5176
GitOrigin-RevId: ea483a755daa3fa6a8701f9d3dd0f393bc56510f
This commit is contained in:
Samir Talwar 2022-07-27 15:29:06 +02:00 committed by hasura-bot
parent 1f574c6eaf
commit 4f85976155
2 changed files with 61 additions and 8 deletions

View File

@ -30,6 +30,21 @@ DOCKER_COMPOSE = $(error "Could not find docker-compose.")
endif
endif
ifneq ($(shell command -v sqlcmd),)
MSSQL_SQLCMD = sqlcmd
MSSQL_SQLCMD_PORT = $(MSSQL_PORT)
else
ifneq ($(shell [[ -e /opt/mssql-tools/bin/sqlcmd ]] && echo true),)
MSSQL_SQLCMD = /opt/mssql-tools/bin/sqlcmd
MSSQL_SQLCMD_PORT = $(MSSQL_PORT)
else
MSSQL_SQLCMD = docker exec $(shell basename $(PWD))-sqlserver-1 sqlcmd
MSSQL_SQLCMD_PORT = 1433
endif
endif
export MSSQL_SQLCMD
define stop_after
@ echo $1 >&2
@ $1 || EXIT_STATUS=$$?; \
@ -43,34 +58,72 @@ endef
.PHONY: start-postgres
## start-postgres: start local PostgreSQL DB in Docker and wait for it to be ready
start-postgres:
start-postgres: spawn-postgres wait-for-postgres
.PHONY: spawn-postgres
spawn-postgres:
$(DOCKER_COMPOSE) up -d postgres
.PHONY: wait-for-postgres
wait-for-postgres:
$(DB_UTILS) wait_for_postgres $(PG_PORT)
$(DB_UTILS) wait_for_postgres_db $(PG_PORT) "$(PG_DBNAME)" "$(PG_DBUSER)" "$(PG_DBPASSWORD)"
.PHONY: start-citus
## start-citus: start local Citus DB in Docker and wait for it to be ready
start-citus:
start-citus: spawn-citus wait-for-citus
.PHONY: spawn-citus
spawn-citus:
$(DOCKER_COMPOSE) up -d citus
.PHONY: wait-for-citus
wait-for-citus:
$(DB_UTILS) wait_for_postgres $(CITUS_PORT)
$(DB_UTILS) wait_for_postgres_db $(CITUS_PORT) "$(PG_DBNAME)" "$(PG_DBUSER)" "$(PG_DBPASSWORD)"
.PHONY: start-sqlserver
## start-sqlserver: start local MS SQL Server DB in Docker and wait for it to be ready
start-sqlserver:
start-sqlserver: spawn-sqlserver wait-for-sqlserver
.PHONY: spawn-sqlserver
spawn-sqlserver:
$(DOCKER_COMPOSE) up -d sqlserver
.PHONY: wait-for-sqlserver
wait-for-sqlserver:
$(DB_UTILS) wait_for_mssql $(MSSQL_PORT)
$(DB_UTILS) wait_for_mssql_db $(MSSQL_PORT) "$(MSSQL_DBNAME)" "$(MSSQL_DBUSER)" "$(MSSQL_DBPASSWORD)"
$(DB_UTILS) wait_for_mssql_db $(MSSQL_SQLCMD_PORT) "$(MSSQL_DBNAME)" "$(MSSQL_DBUSER)" "$(MSSQL_DBPASSWORD)"
.PHONY: start-mysql
## start-mysql: start local MariaDB in Docker and wait for it to be ready
start-mysql:
start-mysql: spawn-mysql wait-for-mysql
.PHONY: spawn-mysql
spawn-mysql:
$(DOCKER_COMPOSE) up -d mariadb
.PHONY: wait-for-mysql
wait-for-mysql:
$(DB_UTILS) wait_for_mysql $(MYSQL_PORT) "$(MYSQL_DBNAME)" "$(MYSQL_DBUSER)" "$(MYSQL_DBPASSWORD)"
.PHONY: start-dc-reference-agent
## start-mysql: start the Data Connectors reference agent in Docker and wait for it to be ready
start-dc-reference-agent: spawn-dc-reference-agent wait-for-dc-reference-agent
.PHONY: spawn-dc-reference-agent
spawn-dc-reference-agent:
$(DOCKER_COMPOSE) up -d dc-reference-agent
# This target is probably unncessary, but there to follow the pattern.
.PHONY: wait-for-dc-reference-agent
wait-for-dc-reference-agent:
.PHONY: start-backends
## start-backends: start local PostgreSQL, MariaDB, and MS SQL Server in Docker and wait for them to be ready
start-backends: start-postgres start-sqlserver start-mysql start-citus
start-backends: \
spawn-postgres spawn-sqlserver spawn-mysql spawn-citus spawn-dc-reference-agent \
wait-for-postgres wait-for-sqlserver wait-for-mysql wait-for-citus wait-for-dc-reference-agent
.PHONY: stop-everything
## stop-everything: tear down test databases

View File

@ -7,13 +7,13 @@ test-bigquery: start-postgres remove-tix-file
.PHONY: test-sqlserver
## test-sqlserver: run tests for SQL Server backend
test-sqlserver: start-postgres start-sqlserver remove-tix-file
test-sqlserver: spawn-postgres spawn-sqlserver wait-for-postgres wait-for-sqlserver remove-tix-file
$(call stop_after, \
cabal run tests-hspec -- -m 'SQLServer')
.PHONY: test-mysql
## test-mysql: run tests for MySQL backend
test-mysql: start-postgres start-mysql remove-tix-file
test-mysql: spawn-postgres spawn-mysql wait-for-postgres wait-for-mysql remove-tix-file
$(call stop_after, \
cabal run tests-hspec -- -m 'MySQL')