#!/usr/bin/env bash # Aborts a streaming request from the client side N times and asks the stub what happened to the # upstream HTTP stream: closed (abortedByClient) or left open. Usage: cancel-upstream.sh [app args] source "$(dirname "$0")/lib.sh"; set +e DELAY=${1:-20}; RUNS=${2:-10}; shift 2 stop_all; start_stub "$DELAY"; start_app "$@" echo "== chunk delay ${DELAY} ms, ${RUNS} runs, app args: ${*:-(none)}" closed=0; open=0 for r in $(seq 1 "$RUNS"); do b=$(curl -s "localhost:$STUB_PORT/stub/stats" | sed 's/.*abortedByClient=//') curl -sN --max-time 1 "localhost:$APP_PORT/chat/stream?message=big%20400&turn=$r" >/dev/null sleep 2 a=$(curl -s "localhost:$STUB_PORT/stub/stats" | sed 's/.*abortedByClient=//') if [ "$a" -gt "$b" ]; then closed=$((closed+1)); res=closed; else open=$((open+1)); res="LEFT OPEN"; fi echo "run $r: upstream $res" done echo "upstream closed: $closed of $RUNS, left open: $open of $RUNS" stop_all