121 lines
3.1 KiB
Bash
Executable File
121 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
BINARY_PATH=$GOPATH/bin
|
|
MEETINGIM_BINARY=$BINARY_PATH/server
|
|
|
|
# Kills and removes any running containers.
|
|
cleanup() {
|
|
./run-cluster.sh stop
|
|
if [ -f "./server" ]; then
|
|
rm ./server
|
|
fi
|
|
docker stop mysql && docker rm mysql
|
|
}
|
|
|
|
# Reports failure.
|
|
fail() {
|
|
cleanup
|
|
echo "**************************************************"
|
|
printf "Tests Failed: ${@}\n"
|
|
echo "**************************************************"
|
|
exit 1
|
|
}
|
|
|
|
# Reports success.
|
|
pass() {
|
|
cleanup
|
|
echo "**************************************************"
|
|
echo "* OK *"
|
|
echo "**************************************************"
|
|
exit 0
|
|
}
|
|
|
|
# Brings up a mysql docker container.
|
|
setup() {
|
|
docker info 1>/dev/null 2>&1 || (echo "docker not running" && return 1)
|
|
docker run -p 3306:3306 --name mysql --env MYSQL_ALLOW_EMPTY_PASSWORD=yes -d mysql:5.7 || return 1
|
|
# This fails to detect when the mysql is actually ready.
|
|
# TODO: figure out why.
|
|
#until nc -z -v -w30 localhost 3306; do
|
|
# echo "Waiting for database connection..."
|
|
# sleep 1
|
|
#done
|
|
echo -n "Waiting for mysql to come up."
|
|
while ! mysqladmin ping -u root -h 127.0.0.1 --silent; do
|
|
echo -n "."
|
|
sleep 1
|
|
done
|
|
# Make sure there's no MeetingIM server binary in the current directory.
|
|
if [ -f "./server" ]; then
|
|
rm ./server
|
|
fi
|
|
}
|
|
|
|
# Compiles MeetingIM binaries.
|
|
build() {
|
|
go install -tags mysql -ldflags "-X main.buildstamp=`date -u '+%Y%m%dT%H:%M:%SZ'`" \
|
|
github.com/tinode/chat/tinode-db \
|
|
github.com/tinode/chat/server && \
|
|
ln -s $MEETINGIM_BINARY
|
|
}
|
|
|
|
# Initializes MeetingIM database.
|
|
init-db() {
|
|
$GOPATH/bin/tinode-db -config=./meetingim.conf -data=../tinode-db/data.json
|
|
}
|
|
|
|
wait-for() {
|
|
local port=$1
|
|
while ! nc -z localhost $port; do
|
|
sleep 1
|
|
done
|
|
}
|
|
|
|
# Brings up a three-node MeetingIM cluster.
|
|
run-server() {
|
|
./run-cluster.sh -s "" start && wait-for 16060
|
|
}
|
|
|
|
send-requests() {
|
|
local expect=12
|
|
local port=$1
|
|
local id=$2
|
|
local outfile=$(mktemp /tmp/meetingim-${id}.txt)
|
|
pushd .
|
|
cd ../tn-cli
|
|
python3 tn-cli.py --host=localhost:${port} --no-login < sample-script.txt > $outfile || fail "Test script failed (instance port ${port})"
|
|
popd
|
|
num_positive_responses=`grep -c '<= 20[0-9]' $outfile`
|
|
if [ $num_positive_responses -ne expect ]
|
|
then
|
|
fail "Instance ${port}: unexpected number of 20X responses: ${num_positive_responses} (expected ${expected}). Log file ${outfile}"
|
|
fi
|
|
rm $outfile
|
|
}
|
|
|
|
# Catch unexpected failures, do cleanup and output an error message
|
|
trap 'cleanup ; fail "For Unexpected Reasons"'\
|
|
HUP INT QUIT PIPE TERM
|
|
|
|
# Normal script termination.
|
|
#trap 'cleanup'\
|
|
# EXIT
|
|
|
|
run_id=`date +%s`
|
|
echo "+----------------------------------------------------+"
|
|
echo "| MeetingIM sanity test. |"
|
|
echo "+----------------------------------------------------+"
|
|
echo "Timestamp = ${run_id}"
|
|
|
|
setup || fail "Test setup failed."
|
|
build || fail "Could not build MeetingIM binaries"
|
|
init-db || fail "Could not initialize MeetingIM database"
|
|
run-server || fail "Could not start meetingim"
|
|
|
|
# Test requests.
|
|
send-requests 16060 $run_id
|
|
send-requests 16061 $run_id
|
|
send-requests 16062 $run_id
|
|
|
|
pass
|