From ea4a929fa9123c6c820ec8703bb77d3d44cbeacc Mon Sep 17 00:00:00 2001 From: Kieren Evans Date: Wed, 9 Feb 2022 00:45:36 +0200 Subject: [PATCH] fix: allow 10 seconds to shutdown, fixing shutdown error (#204) * Allow 15 seconds to shut down v2.0.0 and above crashes with message "Error during shutdowncontext deadline exceeded" and exit code 1 upon SIGINT being received. v1.2.1 seems to be unaffected. * Add bats test * Reduce to 10 seconds, define directly Co-Authored-By: andytson-inviqa * style: gofmt -s * chore: bump golang to 1.17 and fix golangci Co-authored-by: andytson-inviqa Co-authored-by: Enrico Stahn --- Makefile | 2 +- README.md | 2 +- cmd/server.go | 2 +- test/e2e.bats | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d8a1932..59ed2a9 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ test-coverage-html: ## Create a code coverage report in HTML go tool cover -html .cover/cover.out test-e2e: - bats tests/e2e.bats + bats test/e2e.bats lint: ## Run linters golangci-lint run diff --git a/README.md b/README.md index 941ad77..0854843 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ brew install docker-compose bats-core kaos/shell/bats-assert kaos/shell/bats-sup After the components are installed run the E2E tests: ```bash -make tests-e2e +make test-e2e ``` ## Contributing diff --git a/cmd/server.go b/cmd/server.go index 6778f03..d1d8202 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -102,7 +102,7 @@ to quickly create a Cobra application.`, <-c // Create a deadline to wait for. - var wait time.Duration + wait := time.Second * 10 ctx, cancel := context.WithTimeout(context.Background(), wait) defer cancel() // Doesn't block if no connections, but will otherwise wait diff --git a/test/e2e.bats b/test/e2e.bats index 4be208c..2fd847c 100644 --- a/test/e2e.bats +++ b/test/e2e.bats @@ -32,3 +32,8 @@ teardown() { assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm2:9000/status"} 1' assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm3:9000/status"} 1' } + +@test "Should exit cleanly" { + run docker-compose -f ./test/docker-compose-e2e.yml stop exporter + docker-compose -f ./test/docker-compose-e2e.yml ps exporter | grep -q "Exit 0" +}