From 56e1f2e30e0447564cbcd297154bb0db5588dca3 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 6 Oct 2021 10:33:01 -0400 Subject: [PATCH 1/4] add convenience make targets for testing --- .circleci/config.yml | 7 ++----- Makefile | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 Makefile diff --git a/.circleci/config.yml b/.circleci/config.yml index bab1dd08ef..53b849db90 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,11 +40,8 @@ jobs: name: Wait for redis command: dockerize -wait tcp://localhost:6379 -timeout 1m - run: - name: go_test with race - command: go test -tags race --race --timeout 60s -v ./... - - run: - name: go_test - command: go test -tags all --timeout 60s -v ./... + name: Tests + command: make test build_binaries: docker: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..52992029a1 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ +.PHONY: test +#: run all tests +test: test_with_race test_all + +.PHONY: test_with_race +#: run only tests tagged with potential race conditions +test_with_race: + @echo + @echo "+++ testing - race conditions?" + @echo + go test -tags race --race --timeout 60s -v ./... + +.PHONY: test_all +#: run all tests, but with no race condition detection +test_all: + @echo + @echo "+++ testing - all the tests" + @echo + go test -tags all --timeout 60s -v ./... From 558de7289baec7da93f79d1508cb826983ecaba3 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 6 Oct 2021 14:26:29 -0400 Subject: [PATCH 2/4] add dockerize to test targets Check for whether Redis is running with Make, so the dev and CI environments run similarly and show the same warnings. Now the tests can be only "make test"! --- .circleci/config.yml | 12 +----------- Makefile | 40 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 53b849db90..1743b8048f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,17 +31,7 @@ jobs: - image: redis:6 steps: - checkout - - run: - name: install dockerize - command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz - environment: - DOCKERIZE_VERSION: v0.3.0 - - run: - name: Wait for redis - command: dockerize -wait tcp://localhost:6379 -timeout 1m - - run: - name: Tests - command: make test + - run: make test build_binaries: docker: diff --git a/Makefile b/Makefile index 52992029a1..032c4a401a 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules +MAKEFLAGS += --no-builtin-variables + .PHONY: test #: run all tests test: test_with_race test_all .PHONY: test_with_race #: run only tests tagged with potential race conditions -test_with_race: +test_with_race: wait_for_redis @echo @echo "+++ testing - race conditions?" @echo @@ -12,8 +16,40 @@ test_with_race: .PHONY: test_all #: run all tests, but with no race condition detection -test_all: +test_all: wait_for_redis @echo @echo "+++ testing - all the tests" @echo go test -tags all --timeout 60s -v ./... + +.PHONY: wait_for_redis +# wait for Redis to become available for test suite +wait_for_redis: dockerize + @echo + @echo "+++ We need a Redis running to run the tests." + @echo + @echo "Checking with dockerize $(shell ./dockerize --version)" + @./dockerize -wait tcp://localhost:6379 -timeout 30s + +# ensure the dockerize command is available +dockerize: dockerize.tar.gz + tar xzvmf dockerize.tar.gz + +HOST_OS := $(shell uname -s | tr A-Z a-z) +# You can override this version from an environment variable. +DOCKERIZE_VERSION ?= v0.6.1 +DOCKERIZE_RELEASE_ASSET := dockerize-${HOST_OS}-amd64-${DOCKERIZE_VERSION}.tar.gz + +dockerize.tar.gz: + @echo + @echo "+++ Retrieving dockerize tool for Redis readiness check." + @echo + curl --location --silent --show-error \ + --output dockerize.tar.gz \ + https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/${DOCKERIZE_RELEASE_ASSET} \ + && file dockerize.tar.gz | grep --silent gzip + +.PHONY: clean +clean: + rm -f dockerize.tar.gz + rm -f dockerize From 795f6be19506aa11b92d0e8963658871b3ade060 Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 6 Oct 2021 14:52:55 -0400 Subject: [PATCH 3/4] cache the downloaded dockerize in CI --- .circleci/config.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1743b8048f..61d532f01d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,6 +31,15 @@ jobs: - image: redis:6 steps: - checkout + - restore_cache: + keys: + - v1-dockerize-{{ checksum "Makefile" }} + - v1-dockerize- + - run: make dockerize + - save_cache: + key: v1-dockerize-{{ checksum "Makefile" }} + paths: + - dockerize.tar.gz - run: make test build_binaries: From 786a4eb7c1d9bf66ec22985eb09a3e601cad3a3f Mon Sep 17 00:00:00 2001 From: Robb Kidd Date: Wed, 6 Oct 2021 14:57:43 -0400 Subject: [PATCH 4/4] cache go dependencies in CI --- .circleci/config.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 61d532f01d..c3351e40e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -40,7 +40,14 @@ jobs: key: v1-dockerize-{{ checksum "Makefile" }} paths: - dockerize.tar.gz + - restore_cache: + keys: + - v3-go-mod-{{ checksum "go.sum" }} - run: make test + - save_cache: + key: v3-go-mod-{{ checksum "go.sum" }} + paths: + - /home/circleci/go/pkg/mod build_binaries: docker: