oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

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.
13set -euo pipefail
14here="$(cd "$(dirname "$0")" && pwd)"
15apple="$here/../../apple"
16conn="$1"; out="$2"; keys="${3:-120}"; mean="${4:-150}"; port="${PORT:-9333}"
17bundle="$apple/.build/out/Products/Release/DocsKitTests.xctest"
18mkdir -p "$out"
19watch_ms=$(( keys * mean + 20000 ))
20
21native() { # 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}
26wait_ready() { for _ in $(seq 1 600); do [ -e "$1.ready" ] && return 0; sleep 0.1; done; echo "never ready: $1" >&2; return 1; }
27
28echo "web -> web"
29node "$here/browser-probe.mjs" "$port" "$conn" web-web "$out/web-web.json" "$keys" "$mean" 0
30
31echo "native -> native"
32rm -f "$out/nn-watch.json.ready"
33native testWatches 1 "$out/nn-watch.json" & w=$!
34wait_ready "$out/nn-watch.json"
35native testTypes 1 "$out/nn-types.json"
36wait $w
37
38echo "native -> web"
39rm -f "$out/nw-watch.json.ready"
40WATCH_MS=$watch_ms node "$here/browser-probe.mjs" "$port" "$conn" web-watches "$out/nw-watch.json" "$keys" "$mean" 2 & w=$!
41wait_ready "$out/nw-watch.json"
42native testTypes 2 "$out/nw-types.json"
43wait $w
44
45echo "web -> native"
46rm -f "$out/wn-watch.json.ready"
47native testWatches 3 "$out/wn-watch.json" & w=$!
48wait_ready "$out/wn-watch.json"
49node "$here/browser-probe.mjs" "$port" "$conn" web-types "$out/wn-types.json" "$keys" "$mean" 3
50wait $w
51
52python3 "$here/join.py" "$out"
53