# Terminates with an error on slow client

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

-- stderr.txt --
level=INFO msg="Reading configuration file" path=karma.yaml
level=INFO msg="Version: dev"
level=INFO msg="Configured Alertmanager source" name=proxied cluster=proxied uri=http://127.0.0.1:9094 proxy=true readonly=false
level=INFO msg="Setting up proxy endpoints" alertmanager=proxied
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=proxied
level=INFO msg="GET request" uri=http://127.0.0.1:9094/metrics timeout=40s
level=ERROR msg="Request failed" error="Get \"http://127.0.0.1:9094/metrics\": dial tcp 127.0.0.1:9094: connect: connection refused" alertmanager=proxied uri=http://127.0.0.1:9094
level=ERROR msg="Collection failed" error="Get \"http://127.0.0.1:9094/api/v2/silences\": dial tcp 127.0.0.1:9094: connect: connection refused" alertmanager=proxied try=1/2
level=INFO msg="GET request" uri=http://127.0.0.1:9094/metrics timeout=40s
level=ERROR msg="Request failed" error="Get \"http://127.0.0.1:9094/metrics\": dial tcp 127.0.0.1:9094: connect: connection refused" alertmanager=proxied uri=http://127.0.0.1:9094
level=ERROR msg="Collection failed" error="Get \"http://127.0.0.1:9094/api/v2/silences\": dial tcp 127.0.0.1:9094: connect: connection refused" alertmanager=proxied 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:8094
level=INFO msg="Shutting down HTTP server" signal=terminated
level=INFO msg="Removing PID file" path=karma.pid
level=ERROR msg="Execution failed" error="shutdown error: context deadline exceeded"
-- karma.yaml --
alertmanager:
  servers:
    - name: proxied
      uri: http://127.0.0.1:9094
      proxy: true
debug: true
listen:
  timeout:
    read: 1m
    write: 1m
-- test.sh --
trap "echo got signal" SIGTERM SIGINT

while [ ! -f karma.pid ]; do sleep 1 ; done
sleep 1
(curl -s --limit-rate 1 http://127.0.0.1:8094/debug/pprof/profile?seconds=35 || echo "curl completed") &
sleep 3
cat karma.pid | xargs kill
while [ -f karma.pid ]; do sleep 1 ; done
killall -v curl || echo "no curl running"
