test.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. # Very basic client testing.
  3. set -e
  4. export BASE_PATH=../../
  5. export LD_LIBRARY_PATH=${BASE_PATH}/lib
  6. export PORT=1888
  7. export SUB_TIMEOUT=1
  8. # Start broker
  9. ../../src/mosquitto -p ${PORT} 2>/dev/null &
  10. export MOSQ_PID=$!
  11. sleep 0.5
  12. # Kill broker on exit
  13. trap "kill $MOSQ_PID" EXIT
  14. # Simple subscribe test - single message from $SYS
  15. ${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C 1 -t '$SYS/broker/uptime' >/dev/null
  16. echo "Simple subscribe ok"
  17. # Simple publish/subscribe test - single message from mosquitto_pub
  18. ${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C 1 -t 'single/test' >/dev/null &
  19. export SUB_PID=$!
  20. ${BASE_PATH}/client/mosquitto_pub -p ${PORT} -t 'single/test' -m 'single-test'
  21. kill ${SUB_PID} 2>/dev/null || true
  22. echo "Simple publish/subscribe ok"
  23. # Publish a file and subscribe, do we get at least that many lines?
  24. export TEST_LINES=$(wc -l test.sh | cut -d' ' -f1)
  25. ${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C ${TEST_LINES} -t 'file-publish' >/dev/null &
  26. export SUB_PID=$!
  27. ${BASE_PATH}/client/mosquitto_pub -p ${PORT} -t 'file-publish' -f ./test.sh
  28. kill ${SUB_PID} 2>/dev/null || true
  29. echo "File publish ok"
  30. # Publish a file from stdin and subscribe, do we get at least that many lines?
  31. export TEST_LINES=$(wc -l test.sh | cut -d' ' -f1)
  32. ${BASE_PATH}/client/mosquitto_sub -p ${PORT} -W ${SUB_TIMEOUT} -C ${TEST_LINES} -t 'file-publish' >/dev/null &
  33. export SUB_PID=$!
  34. ${BASE_PATH}/client/mosquitto_pub -p ${PORT} -t 'file-publish' -l < ./test.sh
  35. kill ${SUB_PID} 2>/dev/null || true
  36. echo "stdin publish ok"