run.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/bin/bash
  2. [ "$DEBUG" ] && set -x
  3. set -eo pipefail
  4. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  5. image="$1"
  6. # Use a client image with curl for testing
  7. clientImage='buildpack-deps:stretch-curl'
  8. app1id="$(docker run -d "$image" rapidoid.port=80 id=app1 app.services=ping,status)"
  9. app2id="$(docker run -d "$image" rapidoid.port=80 id=app2 app.services=ping,status)"
  10. proxyid="$(docker run -d --link "$app1id":app1 --link "$app2id":app2 "$image" rapidoid.port=80 '/ -> http://app1, http://app2' app.services=ping)"
  11. trap "docker rm -vf $proxyid $app1id $app2id > /dev/null" EXIT
  12. _request() {
  13. local cid="$1"
  14. shift
  15. local method="$1"
  16. shift
  17. local url="${1#/}"
  18. shift
  19. docker run --rm --link "$cid":rapidoid "$clientImage" \
  20. curl -fs -X"$method" "$@" "http://rapidoid/$url"
  21. }
  22. # Make sure all Rapidoid servers are listening on port 80
  23. for cid in $app1id $app2id $proxyid; do
  24. . "$dir/../../retry.sh" --tries 40 --sleep 0.25 '[ "$(_request '$cid' GET /rapidoid/ping --output /dev/null || echo $?)" != 7 ]'
  25. done
  26. # Make sure that the round-robin load balancing works properly
  27. for n in `seq 1 5`; do
  28. for i in 1 2; do
  29. [[ "$(_request $cid GET "/rapidoid/status")" == *"\"app$i\""* ]]
  30. done
  31. done