Makefile: make test run more safe

This patch suggests small improvements for the previously committed (very nice <3) unit test helper

 * Use non-default ports for postgres + cockroach. This would help to run same services for ad-hoc unit test (for IDE development for example)
 * Use the same flags for cockroach what we use for unit tests (mem store supposed to make tests faster)
 * Use `docker-compose down -v` for removing all networks and annynmous volumes
 * Remove connection limit (I have seen related problems in my jenkins runs)
 * Omit unused databases to avoid getting failures (eg. omit psql when crdb is used)
 * Do not drop cockroach database (full database will be dropped, anyway...): it also makes testing faster

Change-Id: Iadc04f8617a2825ea4f10072bd023a9c86883680
This commit is contained in:
Márton Elek 2022-05-26 11:27:52 +02:00 committed by Storj Robot
parent ffbb43ddbc
commit 7c854fcde4
2 changed files with 33 additions and 28 deletions

View File

@ -156,6 +156,7 @@ TEST_TARGET ?= "./..."
.PHONY: test/setup
test/setup:
@docker compose -f docker-compose.tests.yaml down -v --remove-orphans ## cleanup previous data
@docker compose -f docker-compose.tests.yaml up -d
@sleep 3
@docker exec -it storj-crdb1-1 bash -c 'cockroach sql --insecure -e "create database testcockroach;"'
@ -166,42 +167,47 @@ test/setup:
@docker exec -it storj-crdb4-1 bash -c 'cockroach sql --insecure -e "create database testmetabase;"'
@docker exec -it storj-postgres-1 bash -c 'echo "postgres" | psql -U postgres -c "create database teststorj;"'
@docker exec -it storj-postgres-1 bash -c 'echo "postgres" | psql -U postgres -c "create database testmetabase;"'
@docker exec -it storj-postgres-1 bash -c 'echo "postgres" | psql -U postgres -c "ALTER ROLE postgres CONNECTION LIMIT -1;"'
.PHONY: test/postgres
test/postgres: test/setup ## Run tests against Postgres (developer)
@env \
STORJ_TEST_POSTGRES='postgres://postgres:postgres@localhost/teststorj?sslmode=disable' \
STORJ_TEST_POSTGRES='postgres://postgres:postgres@localhost:5532/teststorj?sslmode=disable' \
STORJ_TEST_COCKROACH='omit' \
STORJ_TEST_LOG_LEVEL='info' \
go test -tags noembed -parallel 4 -p 6 -vet=off -race -v -cover -coverprofile=.coverprofile $(TEST_TARGET) || { \
docker compose -f docker-compose.tests.yaml rm -fs; \
docker compose -f docker-compose.tests.yaml down -v; \
}
@docker compose -f docker-compose.tests.yaml rm -fs
@docker compose -f docker-compose.tests.yaml down -v
@echo done
.PHONY: test/cockroach
test/cockroach: test/setup ## Run tests against CockroachDB (developer)
@env \
STORJ_TEST_COCKROACH="cockroach://root@localhost:26256/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26257/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26258/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26259/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH_ALT='cockroach://root@localhost:26260/testcockroach?sslmode=disable' \
STORJ_TEST_COCKROACH_NODROP='true' \
STORJ_TEST_POSTGRES='omit' \
STORJ_TEST_COCKROACH="cockroach://root@localhost:26356/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26357/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26358/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26359/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH_ALT='cockroach://root@localhost:26360/testcockroach?sslmode=disable' \
STORJ_TEST_LOG_LEVEL='info' \
go test -tags noembed -parallel 4 -p 6 -vet=off -race -v -cover -coverprofile=.coverprofile $(TEST_TARGET) || { \
docker compose -f docker-compose.tests.yaml rm -fs; \
docker compose -f docker-compose.tests.yaml down -v; \
}
@docker compose -f docker-compose.tests.yaml rm -fs
@docker compose -f docker-compose.tests.yaml down -v
@echo done
.PHONY: test
test: test/setup ## Run tests against CockroachDB and Postgres (developer)
@env \
STORJ_TEST_POSTGRES='postgres://postgres:postgres@localhost/teststorj?sslmode=disable' \
STORJ_TEST_COCKROACH="cockroach://root@localhost:26256/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26257/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26258/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26259/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH_ALT='cockroach://root@localhost:26260/testcockroach?sslmode=disable' \
STORJ_TEST_COCKROACH_NODROP='true' \
STORJ_TEST_POSTGRES='postgres://postgres:postgres@localhost:5532/teststorj?sslmode=disable' \
STORJ_TEST_COCKROACH="cockroach://root@localhost:26356/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26357/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26358/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH="$$STORJ_TEST_COCKROACH;cockroach://root@localhost:26359/testcockroach?sslmode=disable" \
STORJ_TEST_COCKROACH_ALT='cockroach://root@localhost:26360/testcockroach?sslmode=disable' \
STORJ_TEST_LOG_LEVEL='info' \
go test -tags noembed -parallel 4 -p 6 -vet=off -race -v -cover -coverprofile=.coverprofile $(TEST_TARGET) || { \
docker compose -f docker-compose.tests.yaml rm -fs; \

View File

@ -10,35 +10,34 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
- "5532:5432"
crdb1:
hostname: crdb1
command: [ "start-single-node", "--insecure" ]
command: [ "start-single-node", "--insecure", "--store=type=mem,size=2GiB", "--http-addr=localhost:8086", "--cache=512MiB", "--max-sql-memory=512MiB" ]
image: cockroachdb/cockroach
ports:
- "26256:26257"
- "26356:26257"
crdb2:
hostname: crdb2
command: [ "start-single-node", "--insecure" ]
command: [ "start-single-node", "--insecure", "--store=type=mem,size=2GiB", "--http-addr=localhost:8086", "--cache=512MiB", "--max-sql-memory=512MiB" ]
image: cockroachdb/cockroach
ports:
- "26257:26257"
- "26357:26257"
crdb3:
hostname: crdb3
command: [ "start-single-node", "--insecure" ]
command: [ "start-single-node", "--insecure", "--store=type=mem,size=2GiB", "--http-addr=localhost:8086", "--cache=512MiB", "--max-sql-memory=512MiB" ]
image: cockroachdb/cockroach
ports:
- "26258:26257"
- "26358:26257"
crdb4:
hostname: crdb4
command: [ "start-single-node", "--insecure" ]
command: [ "start-single-node", "--insecure", "--store=type=mem,size=2GiB", "--http-addr=localhost:8086", "--cache=512MiB", "--max-sql-memory=512MiB" ]
image: cockroachdb/cockroach
ports:
- "26259:26257"
- "26359:26257"
crdb5:
hostname: crdb5
command: [ "start-single-node", "--insecure" ]
command: [ "start-single-node", "--insecure", "--store=type=mem,size=2GiB", "--http-addr=localhost:8086", "--cache=512MiB", "--max-sql-memory=512MiB" ]
image: cockroachdb/cockroach
ports:
- "26260:26257"
- "26360:26257"