diff --git a/test/client/Makefile b/test/client/Makefile index 25e07d09..775edf72 100644 --- a/test/client/Makefile +++ b/test/client/Makefile @@ -6,5 +6,6 @@ check : test ptest : test test : ./test.sh + #./test-ws.sh clean: diff --git a/test/client/test-ws.sh b/test/client/test-ws.sh new file mode 100755 index 00000000..0f48dbf5 --- /dev/null +++ b/test/client/test-ws.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Very basic client testing. + + +set -e + +export BASE_PATH=../../ +export LD_LIBRARY_PATH=${BASE_PATH}/lib +export CONFIG=ws.conf +export PORT=1888 +export SUB_TIMEOUT=1 + +# Start broker +../../src/mosquitto -c ${CONFIG} 2>/dev/null & +export MOSQ_PID=$! +sleep 0.5 + +# Kill broker on exit +trap "kill $MOSQ_PID" EXIT + + +# Simple subscribe test - single message from $SYS +${BASE_PATH}/client/mosquitto_sub --ws -p ${PORT} -W ${SUB_TIMEOUT} -C 1 -t '$SYS/broker/version' >/dev/null +echo "Simple subscribe ok" + +# Simple publish/subscribe test - single message from mosquitto_pub +${BASE_PATH}/client/mosquitto_sub --ws -p ${PORT} -W ${SUB_TIMEOUT} -C 1 -t 'single/test' >/dev/null & +export SUB_PID=$! +${BASE_PATH}/client/mosquitto_pub --ws -p ${PORT} -t 'single/test' -m 'single-test' +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) +${BASE_PATH}/client/mosquitto_sub --ws -p ${PORT} -W ${SUB_TIMEOUT} -C ${TEST_LINES} -t 'file-publish' >/dev/null & +export SUB_PID=$! +${BASE_PATH}/client/mosquitto_pub --ws -p ${PORT} -t 'file-publish' -f ./test.sh +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) +${BASE_PATH}/client/mosquitto_sub --ws -p ${PORT} -W ${SUB_TIMEOUT} -C ${TEST_LINES} -t 'file-publish' >/dev/null & +export SUB_PID=$! +${BASE_PATH}/client/mosquitto_pub --ws -p ${PORT} -t 'file-publish' -l < ./test.sh +kill ${SUB_PID} 2>/dev/null || true +echo "stdin publish ok" diff --git a/test/client/ws.conf b/test/client/ws.conf new file mode 100644 index 00000000..e8ede834 --- /dev/null +++ b/test/client/ws.conf @@ -0,0 +1,3 @@ +listener 1888 +protocol websockets +allow_anonymous true