mosquitto/test/client/test.sh

48 lines
1.6 KiB
Bash
Raw Normal View History

2020-09-15 12:18:14 +00:00
#!/bin/bash
# Very basic client testing.
set -e
2020-10-14 09:17:49 +00:00
export BASE_PATH=../../
export LD_LIBRARY_PATH=${BASE_PATH}/lib
2020-09-15 12:18:14 +00:00
export PORT=1888
export SUB_TIMEOUT=1
# Start broker
2020-10-14 09:17:49 +00:00
../../src/mosquitto -p ${PORT} 2>/dev/null &
2020-09-15 12:18:14 +00:00
export MOSQ_PID=$!
sleep 0.5
# Kill broker on exit
trap "kill $MOSQ_PID" EXIT
# Simple subscribe test - single message from $SYS
2020-10-14 09:17:49 +00:00
${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C 1 -t '$SYS/broker/uptime' >/dev/null
2020-09-15 12:18:14 +00:00
echo "Simple subscribe ok"
# Simple publish/subscribe test - single message from mosquitto_pub
2020-10-14 09:17:49 +00:00
${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C 1 -t 'single/test' >/dev/null &
2020-09-15 12:18:14 +00:00
export SUB_PID=$!
2020-10-14 09:17:49 +00:00
${BASE_PATH}/client/mosquitto_pub -p ${PORT} -t 'single/test' -m 'single-test'
2020-09-15 12:18:14 +00:00
kill ${SUB_PID} 2>/dev/null || true
echo "Simple publish/subscribe ok"
# Publish a file and subscribe, do we get at least that many lines?
export TEST_LINES=$(wc -l test.sh | cut -d' ' -f1)
2020-10-14 09:17:49 +00:00
${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C ${TEST_LINES} -t 'file-publish' >/dev/null &
2020-09-15 12:18:14 +00:00
export SUB_PID=$!
2020-10-14 09:17:49 +00:00
${BASE_PATH}/client/mosquitto_pub -p ${PORT} -t 'file-publish' -f ./test.sh
2020-09-15 12:18:14 +00:00
kill ${SUB_PID} 2>/dev/null || true
echo "File publish ok"
# Publish a file from stdin and subscribe, do we get at least that many lines?
export TEST_LINES=$(wc -l test.sh | cut -d' ' -f1)
2020-10-14 09:17:49 +00:00
${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C ${TEST_LINES} -t 'file-publish' >/dev/null &
2020-09-15 12:18:14 +00:00
export SUB_PID=$!
2020-10-14 09:17:49 +00:00
${BASE_PATH}/client/mosquitto_pub -p ${PORT} -t 'file-publish' -l < ./test.sh
2020-09-15 12:18:14 +00:00
kill ${SUB_PID} 2>/dev/null || true
echo "stdin publish ok"