fix: synchronize late-joining players
This commit is contained in:
parent
5c3eba1ad2
commit
2aeaf1d44d
6 changed files with 371 additions and 49 deletions
|
|
@ -96,6 +96,7 @@ readonly -a NETWORK_TESTS=(
|
|||
)
|
||||
|
||||
readonly SESSION_SWITCH_NETWORK_TEST="tests/session_switch_multiplayer_validation.gd"
|
||||
readonly LATE_JOIN_NETWORK_TEST="tests/late_join_multiplayer_validation.gd"
|
||||
|
||||
cleanup() {
|
||||
rm -rf -- "${RUN_ROOT}"
|
||||
|
|
@ -104,7 +105,7 @@ trap cleanup EXIT INT TERM
|
|||
|
||||
usage() {
|
||||
printf \
|
||||
'Usage: %s {quick|full|host|network|session-switch|all|--list}\n' \
|
||||
'Usage: %s {quick|full|host|network|session-switch|late-join|all|--list}\n' \
|
||||
"$0"
|
||||
}
|
||||
|
||||
|
|
@ -290,6 +291,71 @@ run_session_switch_network_test() {
|
|||
fi
|
||||
}
|
||||
|
||||
|
||||
run_late_join_network_test() {
|
||||
local script="${LATE_JOIN_NETWORK_TEST}"
|
||||
local name="${script#tests/}"
|
||||
name="${name%.gd}"
|
||||
local host_root first_root late_root
|
||||
local host_pid first_pid late_pid host_status first_status late_status
|
||||
host_root="$(prepare_root "${name}-host")"
|
||||
first_root="$(prepare_root "${name}-first")"
|
||||
late_root="$(prepare_root "${name}-late")"
|
||||
printf '\n==> %s (host + first client + late client)\n' "${script}"
|
||||
XDG_DATA_HOME="${host_root}/data" \
|
||||
XDG_CONFIG_HOME="${host_root}/config" \
|
||||
XDG_CACHE_HOME="${host_root}/cache" \
|
||||
timeout "${TEST_TIMEOUT_SECONDS}s" "${GODOT_BIN}" \
|
||||
--headless --path "${PROJECT_ROOT}" --script "${script}" -- host \
|
||||
>"${host_root}/output.log" 2>&1 &
|
||||
host_pid=$!
|
||||
if ! wait_for_network_host "${script}" "${host_pid}"; then
|
||||
set +e
|
||||
wait "${host_pid}"
|
||||
host_status=$?
|
||||
set -e
|
||||
printf '%s\n' '-- host output --'
|
||||
sed -n '1,240p' "${host_root}/output.log"
|
||||
printf 'error: host did not become ready (exit %d)\n' \
|
||||
"${host_status}" >&2
|
||||
return 1
|
||||
fi
|
||||
XDG_DATA_HOME="${first_root}/data" \
|
||||
XDG_CONFIG_HOME="${first_root}/config" \
|
||||
XDG_CACHE_HOME="${first_root}/cache" \
|
||||
timeout "${TEST_TIMEOUT_SECONDS}s" "${GODOT_BIN}" \
|
||||
--headless --path "${PROJECT_ROOT}" --script "${script}" -- first \
|
||||
>"${first_root}/output.log" 2>&1 &
|
||||
first_pid=$!
|
||||
sleep 4
|
||||
XDG_DATA_HOME="${late_root}/data" \
|
||||
XDG_CONFIG_HOME="${late_root}/config" \
|
||||
XDG_CACHE_HOME="${late_root}/cache" \
|
||||
timeout "${TEST_TIMEOUT_SECONDS}s" "${GODOT_BIN}" \
|
||||
--headless --path "${PROJECT_ROOT}" --script "${script}" -- late \
|
||||
>"${late_root}/output.log" 2>&1 &
|
||||
late_pid=$!
|
||||
set +e
|
||||
wait "${late_pid}"
|
||||
late_status=$?
|
||||
wait "${first_pid}"
|
||||
first_status=$?
|
||||
wait "${host_pid}"
|
||||
host_status=$?
|
||||
set -e
|
||||
printf '%s\n' '-- host output --'
|
||||
sed -n '1,240p' "${host_root}/output.log"
|
||||
printf '%s\n' '-- first client output --'
|
||||
sed -n '1,240p' "${first_root}/output.log"
|
||||
printf '%s\n' '-- late client output --'
|
||||
sed -n '1,240p' "${late_root}/output.log"
|
||||
if ((host_status != 0 || first_status != 0 || late_status != 0)); then
|
||||
printf 'error: host exited %d; clients exited %d/%d\n' \
|
||||
"${host_status}" "${first_status}" "${late_status}" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_quick() {
|
||||
local test_script
|
||||
for test_script in "${QUICK_TESTS[@]}"; do
|
||||
|
|
@ -317,6 +383,7 @@ run_network() {
|
|||
for test_script in "${NETWORK_TESTS[@]}"; do
|
||||
run_network_test "${test_script}"
|
||||
done
|
||||
run_late_join_network_test
|
||||
run_session_switch_network_test
|
||||
}
|
||||
|
||||
|
|
@ -331,6 +398,8 @@ list_tests() {
|
|||
printf ' %s\n' "${NETWORK_TESTS[@]}"
|
||||
printf '%s\n' 'Two-host session-switch network test:'
|
||||
printf ' %s\n' "${SESSION_SWITCH_NETWORK_TEST}"
|
||||
printf '%s\n' 'Three-peer late-join network test:'
|
||||
printf ' %s\n' "${LATE_JOIN_NETWORK_TEST}"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
|
|
@ -349,6 +418,9 @@ case "${1:-}" in
|
|||
session-switch)
|
||||
run_session_switch_network_test
|
||||
;;
|
||||
late-join)
|
||||
run_late_join_network_test
|
||||
;;
|
||||
all)
|
||||
run_full
|
||||
run_host
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue