php-fpm-exporter/test/e2e.bats
Kieren Evans ea4a929fa9
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 <andytson-inviqa@users.noreply.github.com>

* style: gofmt -s

* chore: bump golang to 1.17 and fix golangci

Co-authored-by: andytson-inviqa <andytson-inviqa@users.noreply.github.com>
Co-authored-by: Enrico Stahn <enrico.stahn@gmail.com>
2022-02-09 09:45:36 +11:00

39 lines
1.3 KiB
Bash

#!/usr/bin/env bats
load '/usr/local/lib/bats-support/load.bash'
load '/usr/local/lib/bats-assert/load.bash'
setup () {
docker-compose -f ./test/docker-compose-e2e.yml up -d
# Workaround to wait for docker to start containers
sleep 5
#go run main.go server --phpfpm.scrape-uri tcp://127.0.0.1:9031/status,tcp://127.0.0.1:9032/status 3>&- &
}
teardown() {
docker-compose -f ./test/docker-compose-e2e.yml stop
docker-compose -f ./test/docker-compose-e2e.yml rm -f
docker-compose -f ./test/docker-compose-e2e.yml down --volumes
}
@test "Should have metrics endpoint" {
run curl -sSL http://localhost:9253/metrics
[ "$status" -eq 0 ]
}
@test "Should have metric phpfpm_up" {
run curl -sSL http://localhost:9253/metrics
assert_output --partial '# TYPE phpfpm_up gauge'
}
@test "Should have scraped multiple PHP-FPM pools" {
run curl -sSL http://localhost:9253/metrics
assert_output --partial 'phpfpm_up{pool="www",scrape_uri="tcp://phpfpm1:9000/status"} 1'
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"
}