| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | # shellcheck disable=SC1091 |
| 6 | . "$SCRIPT_DIR/lib.sh" |
| 7 | |
| 8 | init_workspace "rethinkdb" |
| 9 | trap cleanup EXIT |
| 10 | |
| 11 | RETHINKDB_PORT="$(reserve_port)" |
| 12 | write_env "RETHINKDB_PORT" "$RETHINKDB_PORT" |
| 13 | replace_in_file "$WORKDIR/config/go.d/rethinkdb.conf" "127.0.0.1:28015" "127.0.0.1:${RETHINKDB_PORT}" |
| 14 | |
| 15 | compose_up rethinkdb |
| 16 | wait_healthy rethinkdb 60 |
| 17 | |
| 18 | build_plugin |
| 19 | |
| 20 | wait_port() { |
| 21 | local port="$1" |
| 22 | for _ in $(seq 1 30); do |
| 23 | if python3 - <<PY |
| 24 | import socket |
| 25 | s = socket.socket() |
| 26 | s.settimeout(1) |
| 27 | try: |
| 28 | s.connect(("127.0.0.1", int("${port}"))) |
| 29 | s.close() |
| 30 | raise SystemExit(0) |
| 31 | except Exception: |
| 32 | raise SystemExit(1) |
| 33 | PY |
| 34 | then |
| 35 | return 0 |
| 36 | fi |
| 37 | sleep 2 |
| 38 | done |
| 39 | echo "Timed out waiting for RethinkDB to accept connections on ${port}" >&2 |
| 40 | return 1 |
| 41 | } |
| 42 | |
| 43 | wait_port "$RETHINKDB_PORT" |
| 44 | |
| 45 | run_bg bash -c "cd \"$REPO_ROOT/src/go\" && go run ./tools/functions-validation/seed/rethinkdb/hold.go --addr 127.0.0.1:${RETHINKDB_PORT} --duration 40s" |
| 46 | HOLD_PID="$LAST_BG_PID" |
| 47 | sleep 3 |
| 48 | |
| 49 | run_info_method rethinkdb running-queries |
| 50 | run_running_queries rethinkdb 1 |
| 51 | |
| 52 | if kill -0 "$HOLD_PID" 2>/dev/null; then |
| 53 | kill "$HOLD_PID" |
| 54 | wait "$HOLD_PID" || true |
| 55 | fi |
| 56 | |
| 57 | echo "E2E checks passed for rethinkdb." >&2 |