#!/bin/sh

concurrent=10
requests=10
# guess the pattern
suffix=$(oc get ksvc -n serverless-ksvc-ns0 ksvc0 --template={{.status.url}} | sed 's|http://ksvc0-serverless-ksvc-ns0.||')

while true
do
        tmp=$(mktemp -d)
        for i in $(seq $concurrent)
        do
                n=$((RANDOM % 100))
                ns=serverless-ksvc-ns$n
                ksvc=ksvc0

                echo "http://$ksvc-$ns.$suffix"
                hey -n $requests -c $requests "http://$ksvc-$ns.$suffix?sleep=10000" > $tmp/$i &
        done

        wait

        for i in $(seq $concurrent)
        do
                grep -E "\[200\]\s+$requests\s+responses" $tmp/$i || { echo "No 100% OK responses on http://$ksvc-$ns.$suffix"; cat $tmp/$i; }
        done

        rm -rf $tmp

        sleep 30
done

