From 5dcbc48490eabb42c03a099199333afce320be09 Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Tue, 5 Jun 2018 09:59:14 +0200 Subject: [PATCH] chore(CI): Run stress test async for speed :rocket: --- .gitignore | 1 + .travis.yml | 3 ++- Makefile | 20 +++++++++++++----- scripts/async-run.sh | 19 +++++++++++++++++ scripts/async-wait.sh | 47 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 6 deletions(-) create mode 100755 scripts/async-run.sh create mode 100755 scripts/async-wait.sh diff --git a/.gitignore b/.gitignore index d0f7f3b..554e0e9 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ # log & pid files /*.log /*.pid +/*.success # docker.json [with credentials] /docker.json diff --git a/.travis.yml b/.travis.yml index 733cab9..6f84c31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,10 +29,11 @@ script: - make lint - make vet - make build + - make stress-test-async CONCURRENT_REQUESTS=128 - make coverage - make blackbox-integration-test - - make stress-test CONCURRENT_REQUESTS=96 - make docker-image DOCKER_TAG=release + - make stress-test-wait TIME=120 MODE=silent after_script: - sudo killall -v dockerd diff --git a/Makefile b/Makefile index 2e9812a..12c6f1b 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ API_VERSION:=$(shell cat API_VERSION) -.PHONY: default PHONY clean offline prepare dep test unit-test whitebox-integration-test coverage blackbox-integration-test \ - shell-test-alpine shell-test-wrong-image shell-test-docker-socket shell-test-docker-tcp shell-test-pullpush start-local-registry stop-local-registry push-to-local-registry \ - stress-test lint vet fail-on-errors docker-image build xbuild changelog release validate-release deploy deploy-github deploy-docker poc-app wrapper install +.PHONY: default PHONY clean offline prepare dep test unit-test whitebox-integration-test coverage blackbox-integration-test shell-test-alpine shell-test-wrong-image shell-test-docker-socket shell-test-docker-tcp shell-test-pullpush start-local-registry stop-local-registry push-to-local-registry stress-test stress-test-async stress-test-wait lint vet fail-on-errors docker-image build xbuild changelog release validate-release deploy deploy-github deploy-docker poc-app wrapper install default: prepare dep test lint vet build PHONY: - @egrep "^[0-9a-zA-Z_\-]+:( |$$)" Makefile | cut -d":" -f1 | uniq | tr '\n' ' ' | sed 's/^/.PHONY: /;s/$$/\n/' + @egrep "^[0-9a-zA-Z_\-]+:( |$$)" Makefile \ + | cut -d":" -f1 | uniq | tr '\n' ' ' | sed 's/^/.PHONY: /;s/ $$//' \ + | xargs -I {} sed -i "s/^\.PHONY:.*$$/{}/" Makefile clean: - rm -rf ./lstags ./dist/ *.log *.pid + git clean -fdx offline: unit-test lint vet build @@ -79,6 +79,16 @@ stress-test: CONCURRENT_REQUESTS:=64 stress-test: ./lstags --yaml-config=${YAML_CONFIG} --concurrent-requests=${CONCURRENT_REQUESTS} +stress-test-async: YAML_CONFIG:=./fixtures/config/config-stress.yaml +stress-test-async: CONCURRENT_REQUESTS:=64 +stress-test-async: + @scripts/async-run.sh stress-test make stress-test YAML_CONFIG=${YAML_CONFIG} CONCURRENT_REQUESTS=${CONCURRENT_REQUESTS} + +stress-test-wait: TIME:=180 +stress-test-wait: MODE:=verbose +stress-test-wait: + @scripts/async-wait.sh stress-test ${TIME} ${MODE} + lint: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -I {} golint {} | tr '`' '|') lint: fail-on-errors diff --git a/scripts/async-run.sh b/scripts/async-run.sh new file mode 100755 index 0000000..33b0bd0 --- /dev/null +++ b/scripts/async-run.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# +if [[ ${#} -lt 2 ]]; then + echo "Usage: ${0} NAME COMMAND [OPTIONS]" + exit 1 +fi + +declare -r NAME=${1}; shift +declare -r EXEC=${@} + +if [[ -f ${NAME}.pid ]]; then + echo "FATAL: ${NAME}.pid file already exists!" + exit 1 +fi + +rm -f ${NAME}.success + +bash -c "${EXEC} && touch ${NAME}.success" &>${NAME}.log & +echo ${!} >${NAME}.pid diff --git a/scripts/async-wait.sh b/scripts/async-wait.sh new file mode 100755 index 0000000..ed37e9c --- /dev/null +++ b/scripts/async-wait.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +# +declare MODES="silent|verbose" + +if [[ ${#} -ne 3 ]]; then + echo "Usage: ${0} NAME TIME ${MODES}" + exit 1 +fi + +declare -r NAME=${1} +declare -r TIME=${2} +declare -r MODE=${3} + +if [[ ! ${MODE} =~ ${MODES} ]]; then + echo "FATAL: Invalid mode: ${MODE} (could be \"${MODES}\")" + exit 1 +fi + +if [[ ! -f ${NAME}.pid ]]; then + echo 'FATAL: nothing to wait for!' + exit 1 +fi + +declare -r W_PID=$(cat ${NAME}.pid) +RUN_TIME=0 +while [[ -e /proc/${W_PID} ]]; do + if [[ ${RUN_TIME} -gt ${TIME} ]]; then + echo; cat ${NAME}.log + echo "ERROR: Timeout reached: ${TIME} seconds" + exit 124 + fi + + sleep 1 + + echo -n . + ((RUN_TIME++)) +done + +if [[ ${MODE} == "verbose" || ! -f ${NAME}.success ]]; then + echo; cat ${NAME}.log +fi + +STATUS=0; [[ -f ${NAME}.success ]] || STATUS=1 + +rm -f ${NAME}.pid ${NAME}.log ${NAME}.success + +exit ${STATUS}