github.com/redhat-appstudio/e2e-tests@v0.0.0-20230619105049-9a422b2094d7/tests/load-tests/run-max-concurrency.sh (about) 1 #!/bin/bash 2 export MY_GITHUB_ORG GITHUB_TOKEN 3 4 load_test() { 5 threads=${1:-1} 6 go run loadtest.go \ 7 --component-repo "${COMPONENT_REPO:-https://github.com/nodeshift-starters/devfile-sample.git}" \ 8 --username "$USER_PREFIX-$(printf "%04d" "$threads")" \ 9 --users 1 \ 10 -w \ 11 -l \ 12 -t "$threads" \ 13 --disable-metrics \ 14 --pipeline-skip-initial-checks="${PIPELINE_SKIP_INITIAL_CHECKS:-true}" 15 } 16 17 USER_PREFIX=${USER_PREFIX:-testuser} 18 # Max length of compliant username is 20 characters. We add "-XXXX-XXXX" suffix for the test users' name so max length of the prefix is 10. 19 # See https://github.com/codeready-toolchain/toolchain-common/blob/master/pkg/usersignup/usersignup.go#L16 20 if [ ${#USER_PREFIX} -gt 10 ]; then 21 echo "Maximal allowed length of user prefix is 10 characters. The '$USER_PREFIX' length of ${#USER_PREFIX} exceeds the limit." 22 exit 1 23 else 24 output=load-tests.max-concurrency.json 25 maxThreads=${MAX_THREADS:-10} 26 threshold=${THRESHOLD:-300} 27 echo '{"maxThreads": '"$maxThreads"', "threshold": '"$threshold"', "maxConcurrencyReached": 0}' | jq >"$output" 28 for t in $(seq 1 "${MAX_THREADS:-10}"); do 29 echo "Deleting resources from previous steps" 30 for res in pipelineruns.tekton.dev components.appstudio.redhat.com componentdetectionqueries.appstudio.redhat.com snapshotenvironmentbindings.appstudio.redhat.com applications.appstudio.redhat.com; do 31 echo -e " * $res" 32 oc get "$res" -A -o json | jq -rc '.items[] | select(.metadata.namespace | startswith("'"$USER_PREFIX"'"))| "oc delete '"$res"' " + .metadata.name + " -n " + .metadata.namespace + ";"' | bash -s 33 done 34 oc get usersignups.toolchain.dev.openshift.com -A -o name | grep "$USER_PREFIX" | xargs oc delete -n toolchain-host-operator 35 attempts=60 36 attempt=1 37 sleep="5s" 38 while [ "$attempt" -le "$attempts" ]; do 39 echo " * Waiting $sleep until all namespaces with '$USER_PREFIX' prefix are gone [attempt $attempt/$attempts]" 40 oc get ns | grep -E "^$USER_PREFIX" >/dev/null 2>&1 || break 1 41 sleep "$sleep" 42 attempt=$((attempt + 1)) 43 done 44 if [ "$attempt" -le "$attempts" ]; then 45 echo " * All the namespaces with '$USER_PREFIX' are gone!" 46 else 47 echo " * WARNING: Timeout waiting for namespaces with '$USER_PREFIX' to be gone. The following namespaces still exist:" 48 oc get ns | grep -E "^$USER_PREFIX" 49 fi 50 load_test "$t" 51 index=$(printf "%04d" "$t") 52 cp -vf load-tests.json "load-tests.max-concurrency.$index.json" 53 cp -vf load-tests.log "load-tests.max-concurrency.$index.log" 54 pipelineRunThresholdExceeded=$(jq -rc ".runPipelineSucceededTimeMax > $threshold" load-tests.json) 55 pipelineRunKPI=$(jq -rc ".runPipelineSucceededTimeMax" load-tests.json) 56 if [ "$pipelineRunThresholdExceeded" = "true" ]; then 57 echo "The maximal time a pipeline run took to succeed (${pipelineRunKPI}s) has exceeded a threshold of ${threshold}s with $t threads." 58 break 59 else 60 jq ".maxConcurrencyReached = $t" "$output" >$$.json && mv -f $$.json "$output" 61 fi 62 done 63 DRY_RUN=false ./clear.sh "$USER_PREFIX" 64 fi