-
-
Notifications
You must be signed in to change notification settings - Fork 21
402 lines (359 loc) · 14.4 KB
/
Copy pathprediction-tests.yml
File metadata and controls
402 lines (359 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
name: Prediction Tests
on:
workflow_dispatch:
inputs:
clientCount:
description: "Total player count to exercise"
required: true
default: "5"
connectionDelaySeconds:
description: "Seconds to wait after server starts before launching clients"
required: true
default: "1"
timeoutMinutes:
description: "Hard timeout for the whole job, in minutes"
required: true
default: "30"
profileTimeoutSeconds:
description: "Seconds before one profile is treated as hung"
required: true
default: "420"
jobTempLeakValidation:
description: "Enable Unity JobTemp allocation diagnostics (high overhead)"
required: false
type: boolean
default: false
jobs:
prediction-tests:
name: ${{ matrix.mode }} mode
runs-on: ubuntu-latest
timeout-minutes: ${{ fromJSON(inputs.timeoutMinutes || '60') }}
strategy:
fail-fast: false
matrix:
# "server" runs a pure server process + N client processes.
# "host" runs a host (server+client in one process) + N-1 client processes.
mode: [server, host]
env:
CLIENT_COUNT: ${{ inputs.clientCount || '5' }}
CONNECT_DELAY: ${{ inputs.connectionDelaySeconds || '1' }}
PROFILE_TIMEOUT_SECONDS: ${{ inputs.profileTimeoutSeconds || '420' }}
JOB_TEMP_LEAK_VALIDATION: ${{ inputs.jobTempLeakValidation && 'true' || 'false' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Restore Library cache
id: cache-library
uses: actions/cache/restore@v4
with:
path: Library
key: Library-PurrDiction-IL2CPP-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-PurrDiction-IL2CPP-
- name: Build StandaloneLinux64 player (IL2CPP)
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
with:
targetPlatform: StandaloneLinux64
buildName: PurrDictionTests
buildsPath: build
unityVersion: auto
# IL2CPP also exercises the FP/prediction IL post-processors through the
# IL -> C++ converter, which surfaces codegen issues Mono tolerates.
customParameters: -standaloneBuildSubtarget Player -scriptingBackend IL2CPP
- name: Save Library cache
if: always() && steps.cache-library.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: Library
key: ${{ steps.cache-library.outputs.cache-primary-key }}
- name: Inspect build output
run: ls -la build/StandaloneLinux64/
- name: Run scenarios
env:
MODE: ${{ matrix.mode }}
run: |
set -u
BIN="$PWD/build/StandaloneLinux64/PurrDictionTests"
sudo chmod +x "$BIN" || chmod +x "$BIN" || true
TOTAL_COUNT="$CLIENT_COUNT"
if [ "$MODE" = "host" ]; then
EXTERNAL_CLIENTS=$((TOTAL_COUNT - 1))
if [ "$EXTERNAL_CLIENTS" -lt 1 ]; then
echo "::error::Host mode needs at least 1 external client (clientCount must be >= 2). Got $TOTAL_COUNT"
exit 1
fi
else
EXTERNAL_CLIENTS="$TOTAL_COUNT"
fi
if ! [[ "$PROFILE_TIMEOUT_SECONDS" =~ ^[0-9]+$ ]] || [ "$PROFILE_TIMEOUT_SECONDS" -lt 30 ]; then
echo "::error::profileTimeoutSeconds must be an integer >= 30. Got '$PROFILE_TIMEOUT_SECONDS'"
exit 1
fi
RUN=(xvfb-run -a --server-args="-screen 0 1024x768x24")
FAIL=0
DIAGNOSTIC_ARGS=()
if [ "$JOB_TEMP_LEAK_VALIDATION" = "true" ]; then
DIAGNOSTIC_ARGS=(-diag-job-temp-memory-leak-validation)
fi
terminate_process_tree() {
local pid="$1"
local child
for child in $(pgrep -P "$pid" 2>/dev/null || true); do
terminate_process_tree "$child"
done
kill -TERM "$pid" 2>/dev/null || true
}
force_kill_process_tree() {
local pid="$1"
local child
for child in $(pgrep -P "$pid" 2>/dev/null || true); do
force_kill_process_tree "$child"
done
kill -KILL "$pid" 2>/dev/null || true
}
run_profile() {
PROFILE="$1"
PORT="$2"
shift 2
LATENCY_ARGS=("$@")
RESULTS_DIR="$PWD/test-results/$PROFILE"
LOGS_DIR="$PWD/test-logs/$PROFILE"
mkdir -p "$RESULTS_DIR" "$LOGS_DIR"
TIMEOUT_MARKER="$RESULTS_DIR/.timed-out"
rm -f "$TIMEOUT_MARKER"
echo "::group::Launching $MODE process ($PROFILE)"
"${RUN[@]}" "$BIN" -batchmode -nographics \
"${DIAGNOSTIC_ARGS[@]}" \
-role "$MODE" -count "$TOTAL_COUNT" -port "$PORT" \
-connectTimeout 180 \
"${LATENCY_ARGS[@]}" \
-results "$RESULTS_DIR/$MODE.json" \
-logFile "$LOGS_DIR/$MODE.log" &
SERVER_PID=$!
echo "$MODE PID: $SERVER_PID"
echo "::endgroup::"
sleep "$CONNECT_DELAY"
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
echo "::error::$MODE process died before clients could start ($PROFILE)"
tail -n 200 "$LOGS_DIR/$MODE.log" || true
FAIL=1
return
fi
READY=0
for _ in $(seq 1 60); do
if grep -q '\[PredictionTests\].*local connection ready' "$LOGS_DIR/$MODE.log" 2>/dev/null; then
READY=1
break
fi
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
break
fi
sleep 1
done
if [ "$READY" -ne 1 ]; then
echo "::error::$MODE process did not become locally ready before clients started ($PROFILE)"
tail -n 200 "$LOGS_DIR/$MODE.log" || true
terminate_process_tree "$SERVER_PID"
wait "$SERVER_PID" 2>/dev/null || true
FAIL=1
return
fi
CLIENT_PIDS=()
for i in $(seq 1 "$EXTERNAL_CLIENTS"); do
echo "::group::Launching client $i ($PROFILE)"
"${RUN[@]}" "$BIN" -batchmode -nographics \
"${DIAGNOSTIC_ARGS[@]}" \
-role client -count "$TOTAL_COUNT" -port "$PORT" \
-connectTimeout 180 \
"${LATENCY_ARGS[@]}" \
-results "$RESULTS_DIR/client-$i.json" \
-logFile "$LOGS_DIR/client-$i.log" &
PID=$!
CLIENT_PIDS+=("$PID")
echo "Client $i PID: $PID"
echo "::endgroup::"
if [ "$i" -lt "$EXTERNAL_CLIENTS" ]; then
sleep 1
fi
done
ALL_PIDS=("$SERVER_PID" "${CLIENT_PIDS[@]}")
(
sleep "$PROFILE_TIMEOUT_SECONDS"
echo "::error::$MODE profile '$PROFILE' exceeded ${PROFILE_TIMEOUT_SECONDS}s; terminating test processes"
date -u > "$TIMEOUT_MARKER"
for pid in "${ALL_PIDS[@]}"; do
terminate_process_tree "$pid"
done
sleep 10
for pid in "${ALL_PIDS[@]}"; do
force_kill_process_tree "$pid"
done
) &
WATCHDOG_PID=$!
for pid in "${CLIENT_PIDS[@]}"; do
if wait "$pid"; then
echo "Client PID $pid exited 0 ($PROFILE)"
else
code=$?
echo "::error::Client PID $pid exited $code ($PROFILE)"
FAIL=1
fi
done
if wait "$SERVER_PID"; then
echo "$MODE process exited 0 ($PROFILE)"
else
code=$?
echo "::error::$MODE process exited $code ($PROFILE)"
FAIL=1
fi
if kill -0 "$WATCHDOG_PID" 2>/dev/null; then
kill "$WATCHDOG_PID" 2>/dev/null || true
fi
wait "$WATCHDOG_PID" 2>/dev/null || true
if [ -f "$TIMEOUT_MARKER" ]; then
echo "::error::$MODE profile '$PROFILE' timed out after ${PROFILE_TIMEOUT_SECONDS}s"
FAIL=1
echo "::group::Logs at timeout ($PROFILE)"
for f in "$LOGS_DIR"/*.log; do
[ -e "$f" ] || continue
echo "----- $f (last 200 lines) -----"
tail -n 200 "$f" || true
done
echo "::endgroup::"
fi
echo "::group::Result files ($PROFILE)"
for f in "$RESULTS_DIR"/*.json; do
[ -e "$f" ] || continue
echo "----- $f -----"
cat "$f"
echo
done
echo "::endgroup::"
if command -v jq >/dev/null 2>&1; then
for f in "$RESULTS_DIR"/*.json; do
[ -e "$f" ] || continue
if jq -e 'any(.[]; .result.success == false)' "$f" >/dev/null; then
echo "::error::$f contains a failed scenario"
FAIL=1
fi
done
fi
}
run_profile default 37001 -latencyMin 40 -latencyMax 80
run_profile no-latency 37002 -latencyMax 0
run_profile high-jitter 37003 -latencyMin 120 -latencyMax 250
run_profile loss 37004 -latencyMin 40 -latencyMax 80 -packetLoss 5
run_profile heavy-loss 37005 -latencyMin 80 -latencyMax 160 -packetLoss 15
run_profile input-bandwidth-budget 37009 -inputBandwidthBenchmark -ibSeconds 12 -ibNoise constant -ibAssert -tickRate 64 -latencyMin 70 -latencyMax 70
run_profile purrleague-immediate-rpc 37006 -tickRate 60 -mtuFragment -desyncPolicy Report -immediateRpcRegressionScenarioOnly
run_profile webtransport-immediate-rpc 37007 -tickRate 60 -mtuFragment -desyncPolicy Report -webTransport -immediateRpcRegressionScenarioOnly
run_profile purrleague-immediate-rpc-no-player 37008 -tickRate 60 -mtuFragment -desyncPolicy Report -immediateRpcRegressionScenarioOnly -immediateRpcRegressionWithoutPlayer
exit $FAIL
- name: Render results to job summary
if: always()
env:
MODE: ${{ matrix.mode }}
run: |
set -u
shopt -s globstar nullglob
files=(test-results/**/*.json)
if [ ${#files[@]} -eq 0 ]; then
{
echo "## Prediction Test Results"
echo ""
echo "_No result files were produced._"
} >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
JQ_LIB='
def humanBytes:
if . == null then "—"
elif . < 1024 then "\(.) B"
elif . < 1048576 then "\(((. * 10) / 1024 | floor) / 10) KB"
else "\(((. * 100) / 1048576 | floor) / 100) MB" end;
def humanDuration:
if . == null then "—"
elif . < 1000 then "\(((. * 10) | floor) / 10)ms"
else "\(((. * 100) / 1000 | floor) / 100)s" end;
def statusIcon:
if . then ":white_check_mark:" else ":x:" end;
'
total=0
passed=0
for f in "${files[@]}"; do
count=$(jq 'length' "$f")
pass=$(jq '[.[] | select(.result.success == true)] | length' "$f")
total=$((total + count))
passed=$((passed + pass))
done
failed=$((total - passed))
{
echo "## Prediction Test Results — ${MODE} mode"
echo ""
if [ "$failed" -eq 0 ]; then
echo "### :white_check_mark: All scenarios passed (${passed}/${total})"
else
echo "### :x: ${failed} failure(s) — ${passed}/${total} passed"
fi
echo ""
for f in "${files[@]}"; do
proc="${f#test-results/}"
proc="${proc%.json}"
pcount=$(jq 'length' "$f")
ppass=$(jq '[.[] | select(.result.success == true)] | length' "$f")
pfail=$((pcount - ppass))
case "$proc" in
*/client-*) is_client=1 ;;
*) is_client=0 ;;
esac
if [ "$is_client" -eq 1 ]; then
if [ "$pfail" -eq 0 ]; then
echo "#### \`${proc}\` — ${ppass}/${pcount} passed :white_check_mark:"
echo ""
echo "_All scenarios passed; rows omitted._"
echo ""
continue
fi
echo "#### \`${proc}\` — ${pfail} failed (${ppass}/${pcount} passed)"
else
echo "#### \`${proc}\` — ${ppass}/${pcount} passed"
fi
echo ""
echo "| # | Scenario | Status | Duration | Sent | Received | Message |"
echo "|---|---|---|---|---|---|---|"
FILTER='to_entries[]'
if [ "$is_client" -eq 1 ]; then
FILTER='to_entries[] | select(.value.result.success == false)'
fi
jq -r "$JQ_LIB"'
'"$FILTER"' |
"| \(.key) | \(.value.name // "?") | \(.value.result.success | statusIcon) | \(.value.durationInMs | humanDuration) | \(.value.dataSent | humanBytes) | \(.value.dataReceived | humanBytes) | \((.value.result.message // "") | gsub("\\|"; "|") | gsub("[\\r\\n]+"; " ")) |"
' "$f"
echo ""
done
} >> "$GITHUB_STEP_SUMMARY"
- name: Tail logs on failure
if: failure()
run: |
shopt -s globstar nullglob
for f in test-logs/**/*.log; do
[ -e "$f" ] || continue
echo "::group::$f (last 200 lines)"
tail -n 200 "$f"
echo "::endgroup::"
done
- name: Upload test results and logs
if: always()
uses: actions/upload-artifact@v4
with:
name: prediction-test-artifacts-${{ matrix.mode }}
path: |
test-results/
test-logs/
if-no-files-found: warn
retention-days: 14