#!/usr/bin/env bash # The real clients, end to end: web <-> web (two headless Chrome tabs), native # -> native (two XCTest processes, as two apps), native -> web and web -> # native, against one probe server (run-probe.py SERVER_ONLY=1). # # run-clients.sh [keys] [mean-ms] # # Needs: headless Chrome with --remote-debugging-port=$PORT (default 9333) # and --use-mock-keychain (without it, setting a cookie waits on a keychain # prompt for ever); a release test build of native/apple # (swift build -c release --build-tests -Xswiftc -enable-testing # -Xswiftc -DDOCS_PROBES -Xswiftc -DDEBUG). The server needs four documents. set -euo pipefail here="$(cd "$(dirname "$0")" && pwd)" apple="$here/../../apple" conn="$1"; out="$2"; keys="${3:-120}"; mean="${4:-150}"; port="${PORT:-9333}" bundle="$apple/.build/out/Products/Release/DocsKitTests.xctest" mkdir -p "$out" watch_ms=$(( keys * mean + 20000 )) native() { # test index out DOCS_LIVE_NATIVE_CONN="$conn" DOCS_LIVE_NATIVE_INDEX="$2" DOCS_LIVE_NATIVE_OUT="$3" DOCS_LIVE_NATIVE_KEYS="$keys" \ DOCS_LIVE_NATIVE_MEAN_MS="$mean" WATCH_MS="$watch_ms" TMPDIR=/tmp \ xcrun xctest -XCTest "DocsKitTests.LivePushLatencyTests/$1" "$bundle" > "$3.log" 2>&1 } wait_ready() { for _ in $(seq 1 600); do [ -e "$1.ready" ] && return 0; sleep 0.1; done; echo "never ready: $1" >&2; return 1; } echo "web -> web" node "$here/browser-probe.mjs" "$port" "$conn" web-web "$out/web-web.json" "$keys" "$mean" 0 echo "native -> native" rm -f "$out/nn-watch.json.ready" native testWatches 1 "$out/nn-watch.json" & w=$! wait_ready "$out/nn-watch.json" native testTypes 1 "$out/nn-types.json" wait $w echo "native -> web" rm -f "$out/nw-watch.json.ready" WATCH_MS=$watch_ms node "$here/browser-probe.mjs" "$port" "$conn" web-watches "$out/nw-watch.json" "$keys" "$mean" 2 & w=$! wait_ready "$out/nw-watch.json" native testTypes 2 "$out/nw-types.json" wait $w echo "web -> native" rm -f "$out/wn-watch.json.ready" native testWatches 3 "$out/wn-watch.json" & w=$! wait_ready "$out/wn-watch.json" node "$here/browser-probe.mjs" "$port" "$conn" web-types "$out/wn-types.json" "$keys" "$mean" 3 wait $w python3 "$here/join.py" "$out"