# Fails is we cannot remove a PID file

exec bash -x ./test.sh &
! exec karma --pid-file=karma.pid --alertmanager.uri=http://127.0.0.1:7073 --listen.address=127.0.0.1 --listen.port=8073
! stdout .
cmp stderr stderr.txt
wait

-- stderr.txt --
level=INFO msg="Version: dev"
level=INFO msg="Configured Alertmanager source" name=default cluster=default uri=http://127.0.0.1:7073 proxy=false readonly=false
level=INFO msg="Writing PID file" path=karma.pid
level=INFO msg="Initial Alertmanager collection"
level=INFO msg="Pulling latest alerts and silences from Alertmanager"
level=INFO msg="Collecting alerts and silences" alertmanager=default
level=INFO msg="GET request" uri=http://127.0.0.1:7073/metrics timeout=40s
level=ERROR msg="Request failed" error="Get \"http://127.0.0.1:7073/metrics\": dial tcp 127.0.0.1:7073: connect: connection refused" alertmanager=default uri=http://127.0.0.1:7073
level=ERROR msg="Collection failed" error="Get \"http://127.0.0.1:7073/api/v2/silences\": dial tcp 127.0.0.1:7073: connect: connection refused" alertmanager=default try=1/2
level=INFO msg="GET request" uri=http://127.0.0.1:7073/metrics timeout=40s
level=ERROR msg="Request failed" error="Get \"http://127.0.0.1:7073/metrics\": dial tcp 127.0.0.1:7073: connect: connection refused" alertmanager=default uri=http://127.0.0.1:7073
level=ERROR msg="Collection failed" error="Get \"http://127.0.0.1:7073/api/v2/silences\": dial tcp 127.0.0.1:7073: connect: connection refused" alertmanager=default try=2/2
level=INFO msg="Collection completed"
level=INFO msg="Done, starting HTTP server"
level=INFO msg="Starting HTTP server" address=127.0.0.1:8073
level=INFO msg="Shutting down HTTP server" signal=terminated
level=INFO msg="HTTP server shut down"
level=INFO msg="Removing PID file" path=karma.pid
level=ERROR msg="Execution failed" error="failed to remove PID file: remove karma.pid: no such file or directory"
-- test.sh --
while [ ! -f karma.pid ]; do sleep 1 ; done
sleep 1
PID=$(cat karma.pid)
rm karma.pid
kill $PID
