Skip to content

Commit

Permalink
chore(CI): Run stress test async for speed 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Jun 8, 2018
1 parent d188daa commit 5dcbc48
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# log & pid files
/*.log
/*.pid
/*.success

# docker.json [with credentials]
/docker.json
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions scripts/async-run.sh
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions scripts/async-wait.sh
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 5dcbc48

Please sign in to comment.