Makefile: update test target to support a local execution workflow

This change attempts to run tests as close to CI as possible. It
introduces a docker-compose file that deploys some supporting
services. While this change makes it possible to run tests locally,
it does not address the core time it takes to run tests end to end.

make test/postgres  1417.87s user 263.38s system 291% cpu 9:37.73 total

Resolves https://github.com/storj/dev-enablement/issues/10

Change-Id: I4d9adc125992c1b1c133e8fe108384fa3c66ff7a
This commit is contained in:
Mya 2022-05-19 12:57:04 -05:00 committed by mya
parent c136796308
commit 4b61cc9e9c
3 changed files with 121 additions and 2 deletions

View File

@ -260,6 +260,29 @@ git rebase -i HEAD~3
...
```
## Executing tests locally
The Storj project has an extensive suite of integration tests. Many of these tests require several infrastructure
dependencies. These dependencies are defined and managed by the `docker-compose.tests.yaml` file. Tests can be executed
against Postgres (`test/postgres`), or CockroachDB (`test/cockroach`), or against both (`test`). By default, the full
suite of tests is run, but can be limited using the `TEST_TARGET` make variable.
```sh
# run only against Postgres
make test/postgres TEST_TARGET="./satellite/oidc/..."
```
You can also provide multiple targets for the test harness to run in case your change spans across several packages.
```sh
# run against both Postgres and Cockroach
make test TEST_TARGET="./satellite/oidc/... ./satellite/satellitedb/..."
```
_**Note:** While you can run the full suite of tests locally, you will likely be waiting around for them to complete.
By starting with the tests from packages you have modified, you can build a great deal of confidence in your changes
before pushing them up for review._
## Developing locally with `storj-up`
Following the instructions in the `storj-up` project `README`, the following will deploy a copy of the stack.

View File

@ -104,9 +104,61 @@ install-sim: ## install storj-sim
##@ Test
TEST_TARGET ?= "./..."
.PHONY: test/setup
test/setup:
@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;"'
@docker exec -it storj-crdb2-1 bash -c 'cockroach sql --insecure -e "create database testcockroach;"'
@docker exec -it storj-crdb3-1 bash -c 'cockroach sql --insecure -e "create database testcockroach;"'
@docker exec -it storj-crdb4-1 bash -c 'cockroach sql --insecure -e "create database testcockroach;"'
@docker exec -it storj-crdb5-1 bash -c 'cockroach sql --insecure -e "create database testcockroach;"'
@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;"'
.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_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 rm -fs
@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_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 rm -fs
@echo done
.PHONY: test
test: ## Run tests on source code (jenkins)
go test -race -v -cover -coverprofile=.coverprofile ./...
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_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 rm -fs
@echo done
.PHONY: test-sim

44
docker-compose.tests.yaml Normal file
View File

@ -0,0 +1,44 @@
# Support services used by tests
version: "3.4"
services:
postgres:
hostname: postgres
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
crdb1:
hostname: crdb1
command: [ "start-single-node", "--insecure" ]
image: cockroachdb/cockroach
ports:
- "26256:26257"
crdb2:
hostname: crdb2
command: [ "start-single-node", "--insecure" ]
image: cockroachdb/cockroach
ports:
- "26257:26257"
crdb3:
hostname: crdb3
command: [ "start-single-node", "--insecure" ]
image: cockroachdb/cockroach
ports:
- "26258:26257"
crdb4:
hostname: crdb4
command: [ "start-single-node", "--insecure" ]
image: cockroachdb/cockroach
ports:
- "26259:26257"
crdb5:
hostname: crdb5
command: [ "start-single-node", "--insecure" ]
image: cockroachdb/cockroach
ports:
- "26260:26257"