| 1 | #!/usr/bin/env bash |
| 2 | # The real clients, end to end: web <-> web (two headless Chrome tabs), native |
| 3 | # -> native (two XCTest processes, as two apps), native -> web and web -> |
| 4 | # native, against one probe server (run-probe.py SERVER_ONLY=1). |
| 5 | # |
| 6 | # run-clients.sh <connection.json> <out-dir> [keys] [mean-ms] |
| 7 | # |
| 8 | # Needs: headless Chrome with --remote-debugging-port=$PORT (default 9333) |
| 9 | # and --use-mock-keychain (without it, setting a cookie waits on a keychain |
| 10 | # prompt for ever); a release test build of native/apple |
| 11 | # (swift build -c release --build-tests -Xswiftc -enable-testing |
| 12 | # -Xswiftc -DDOCS_PROBES -Xswiftc -DDEBUG). The server needs four documents. |
| 13 | set -euo pipefail |
| 14 | here="$(cd "$(dirname "$0")" && pwd)" |
| 15 | apple="$here/../../apple" |
| 16 | conn="$1"; out="$2"; keys="${3:-120}"; mean="${4:-150}"; port="${PORT:-9333}" |
| 17 | bundle="$apple/.build/out/Products/Release/DocsKitTests.xctest" |
| 18 | mkdir -p "$out" |
| 19 | watch_ms=$(( keys * mean + 20000 )) |
| 20 | |
| 21 | native() { # test index out |
| 22 | DOCS_LIVE_NATIVE_CONN="$conn" DOCS_LIVE_NATIVE_INDEX="$2" DOCS_LIVE_NATIVE_OUT="$3" DOCS_LIVE_NATIVE_KEYS="$keys" \ |
| 23 | DOCS_LIVE_NATIVE_MEAN_MS="$mean" WATCH_MS="$watch_ms" TMPDIR=/tmp \ |
| 24 | xcrun xctest -XCTest "DocsKitTests.LivePushLatencyTests/$1" "$bundle" > "$3.log" 2>&1 |
| 25 | } |
| 26 | wait_ready() { for _ in $(seq 1 600); do [ -e "$1.ready" ] && return 0; sleep 0.1; done; echo "never ready: $1" >&2; return 1; } |
| 27 | |
| 28 | echo "web -> web" |
| 29 | node "$here/browser-probe.mjs" "$port" "$conn" web-web "$out/web-web.json" "$keys" "$mean" 0 |
| 30 | |
| 31 | echo "native -> native" |
| 32 | rm -f "$out/nn-watch.json.ready" |
| 33 | native testWatches 1 "$out/nn-watch.json" & w=$! |
| 34 | wait_ready "$out/nn-watch.json" |
| 35 | native testTypes 1 "$out/nn-types.json" |
| 36 | wait $w |
| 37 | |
| 38 | echo "native -> web" |
| 39 | rm -f "$out/nw-watch.json.ready" |
| 40 | WATCH_MS=$watch_ms node "$here/browser-probe.mjs" "$port" "$conn" web-watches "$out/nw-watch.json" "$keys" "$mean" 2 & w=$! |
| 41 | wait_ready "$out/nw-watch.json" |
| 42 | native testTypes 2 "$out/nw-types.json" |
| 43 | wait $w |
| 44 | |
| 45 | echo "web -> native" |
| 46 | rm -f "$out/wn-watch.json.ready" |
| 47 | native testWatches 3 "$out/wn-watch.json" & w=$! |
| 48 | wait_ready "$out/wn-watch.json" |
| 49 | node "$here/browser-probe.mjs" "$port" "$conn" web-types "$out/wn-types.json" "$keys" "$mean" 3 |
| 50 | wait $w |
| 51 | |
| 52 | python3 "$here/join.py" "$out" |
| 53 | |