N8: 24-client network soak, and the server fixes it found
make soak runs a real server and 24 headless clients in three processes for two whole matches in real time. Each client reaches the server through its own UdpRelay, which adds 60 ms, +/-20 ms jitter and 2% loss each way, so ENet runs unchanged over a bad link. SoakPlayer drives each client from what a client knows: it drops, glides, heads for high ground, harvests and tries to build. tools/soak_report.gd checks world hashes against the server's, errors, unreadable packets, every client playing every match with its connection intact, memory between matches, and the p99 tick with the network's share. make soak-selfcheck proves a drifted client world is caught. Server changes: --matches=N, --world-hash-every=N, tick timing that includes after_tick, and memory in match and progress lines. What the soak found and fixed: - Snapshot building for 24 clients took the p99 tick to 13.8 ms, over the 12 ms budget, against a 2.8 ms simulation. Encoded records are now shared between clients for the tick, unchanged records skip the field diff, and clients are spread over the snapshot interval by handle. p99 is 7.3 ms. - ENet peers had a timeout limit of 0, which gives up on a peer as soon as any reliable message has waited the minimum timeout. Now ENet's default, 32. Not fixed: one or two clients still lose their connection about 15 s into the second match's drop in each run (see the issue), so the soak still fails and N8 stays open. Refs #39 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
extends TestCase
|
||||
|
||||
## Issue N8: the soak test's bad network. UdpRelay delays, loses and counts datagrams
|
||||
## both ways, ignores strangers, and the game's real transport still joins through it.
|
||||
|
||||
const HOST: String = "127.0.0.1"
|
||||
|
||||
var relay: UdpRelay
|
||||
var server_socket: PacketPeerUDP
|
||||
var client_socket: PacketPeerUDP
|
||||
|
||||
|
||||
func before_each() -> void:
|
||||
server_socket = PacketPeerUDP.new()
|
||||
assert_eq(server_socket.bind(0, HOST), OK)
|
||||
client_socket = PacketPeerUDP.new()
|
||||
relay = null
|
||||
|
||||
|
||||
func after_each() -> void:
|
||||
if relay != null:
|
||||
relay.close()
|
||||
server_socket.close()
|
||||
client_socket.close()
|
||||
|
||||
|
||||
func _open(latency: float, jitter: float, loss: float) -> void:
|
||||
relay = UdpRelay.new(latency, jitter, loss, 7)
|
||||
assert_eq(relay.open(0, HOST, server_socket.get_local_port()), OK)
|
||||
assert_eq(client_socket.connect_to_host(HOST, relay.port()), OK)
|
||||
|
||||
|
||||
## Waits a little for loopback datagrams to land, then polls the relay at `now`.
|
||||
func _settle_and_poll(now: int) -> void:
|
||||
OS.delay_msec(20)
|
||||
relay.poll(now)
|
||||
|
||||
|
||||
func test_delays_both_ways() -> void:
|
||||
_open(100.0, 0.0, 0.0)
|
||||
client_socket.put_packet(PackedByteArray([1, 2, 3]))
|
||||
_settle_and_poll(1000)
|
||||
assert_eq(relay.in_flight(), 1, "held, not passed on at once")
|
||||
relay.poll(1099)
|
||||
OS.delay_msec(20)
|
||||
assert_eq(server_socket.get_available_packet_count(), 0, "not before its time")
|
||||
relay.poll(1100)
|
||||
OS.delay_msec(20)
|
||||
assert_eq(server_socket.get_available_packet_count(), 1)
|
||||
assert_eq(server_socket.get_packet(), PackedByteArray([1, 2, 3]))
|
||||
# The server answers whoever sent it: the relay's other side.
|
||||
server_socket.set_dest_address(server_socket.get_packet_ip(), server_socket.get_packet_port())
|
||||
server_socket.put_packet(PackedByteArray([9]))
|
||||
_settle_and_poll(2000)
|
||||
relay.poll(2100)
|
||||
OS.delay_msec(20)
|
||||
assert_eq(client_socket.get_available_packet_count(), 1)
|
||||
assert_eq(client_socket.get_packet(), PackedByteArray([9]))
|
||||
assert_eq([relay.up_packets, relay.up_bytes, relay.down_packets, relay.down_bytes], [1, 3, 1, 1])
|
||||
|
||||
|
||||
func test_loss_drops_and_counts() -> void:
|
||||
_open(0.0, 0.0, 1.0)
|
||||
for index: int in 5:
|
||||
client_socket.put_packet(PackedByteArray([index]))
|
||||
_settle_and_poll(0)
|
||||
relay.poll(1)
|
||||
OS.delay_msec(20)
|
||||
assert_eq(relay.up_lost, 5)
|
||||
assert_eq(relay.in_flight(), 0)
|
||||
assert_eq(server_socket.get_available_packet_count(), 0)
|
||||
|
||||
|
||||
func test_jitter_stays_in_range() -> void:
|
||||
_open(50.0, 20.0, 0.0)
|
||||
for index: int in 40:
|
||||
client_socket.put_packet(PackedByteArray([index]))
|
||||
_settle_and_poll(0)
|
||||
assert_eq(relay.in_flight(), 40)
|
||||
relay.poll(29)
|
||||
OS.delay_msec(20)
|
||||
assert_eq(server_socket.get_available_packet_count(), 0, "none sooner than latency less jitter")
|
||||
relay.poll(70)
|
||||
OS.delay_msec(20)
|
||||
assert_eq(server_socket.get_available_packet_count(), 40, "all by latency plus jitter")
|
||||
|
||||
|
||||
func test_ignores_a_second_sender() -> void:
|
||||
_open(0.0, 0.0, 0.0)
|
||||
client_socket.put_packet(PackedByteArray([1]))
|
||||
_settle_and_poll(0)
|
||||
var stranger: PacketPeerUDP = PacketPeerUDP.new()
|
||||
assert_eq(stranger.connect_to_host(HOST, relay.port()), OK)
|
||||
stranger.put_packet(PackedByteArray([2]))
|
||||
_settle_and_poll(1)
|
||||
relay.poll(2)
|
||||
OS.delay_msec(20)
|
||||
stranger.close()
|
||||
assert_eq(relay.up_packets, 1)
|
||||
assert_eq(server_socket.get_available_packet_count(), 1)
|
||||
assert_eq(server_socket.get_packet(), PackedByteArray([1]))
|
||||
|
||||
|
||||
func test_real_transport_joins_through_a_bad_link() -> void:
|
||||
server_socket.close()
|
||||
var server: NetServer = NetServer.new()
|
||||
server.match_seed = 99
|
||||
assert_eq(server.listen(0, HOST), OK)
|
||||
relay = UdpRelay.new(40.0, 15.0, 0.1, 3)
|
||||
assert_eq(relay.open(0, HOST, server.port()), OK)
|
||||
var client: NetClient = NetClient.new()
|
||||
assert_eq(client.connect_to(HOST, relay.port(), "Wren"), OK)
|
||||
var started: int = Time.get_ticks_msec()
|
||||
while client.state != NetClient.JOINED and Time.get_ticks_msec() - started < 8000:
|
||||
server.poll()
|
||||
relay.poll()
|
||||
client.poll()
|
||||
OS.delay_msec(2)
|
||||
assert_eq(client.state_name(), "joined")
|
||||
assert_eq(client.match_seed, 99)
|
||||
assert_true(relay.up_packets > 0 and relay.down_packets > 0)
|
||||
client.leave()
|
||||
server.close()
|
||||
@@ -0,0 +1 @@
|
||||
uid://bue7ocmcipqfq
|
||||
@@ -212,3 +212,19 @@ func test_junk_on_the_game_channel_is_counted_and_changes_nothing() -> void:
|
||||
assert_true(_pump(func() -> bool: return game.bad_inputs >= 20), "%d counted" % game.bad_inputs)
|
||||
assert_eq(mara.state, NetClient.JOINED)
|
||||
assert_true(loop.match_flow.in_match())
|
||||
|
||||
|
||||
func test_snapshots_are_spread_over_the_interval() -> void:
|
||||
# Issue N8: building every client's snapshot on one tick put the whole cost there.
|
||||
var interval: int = Tuning.NET_SNAPSHOT_INTERVAL_TICKS
|
||||
var hits: Dictionary = {}
|
||||
for _tick: int in interval * 10:
|
||||
loop.run_tick()
|
||||
var due: int = 0
|
||||
for handle: int in range(1, 25):
|
||||
if game.snapshot_due_for(handle):
|
||||
due += 1
|
||||
hits[handle] = int(hits.get(handle, 0)) + 1
|
||||
assert_eq(due, 24 / interval, "an even share of 24 clients on every tick")
|
||||
for handle: int in range(1, 25):
|
||||
assert_eq(hits.get(handle, 0), 10, "one snapshot every interval for handle %d" % handle)
|
||||
|
||||
@@ -108,3 +108,14 @@ func test_bad_discovery_options() -> void:
|
||||
assert_false(_parse(["--server", "--listen", wrong]).is_valid(), wrong)
|
||||
assert_false(_parse(["--server", "--list=192.0.2.4"]).is_valid(), "a list server needs --listen")
|
||||
assert_false(_parse(["--server", "--no-lan"]).is_valid())
|
||||
|
||||
|
||||
func test_soak_options() -> void:
|
||||
var config: ServerConfig = _parse(["--server", "--listen", "--matches=2", "--world-hash-every=300"])
|
||||
assert_true(config.is_valid(), str(config.errors))
|
||||
assert_eq(config.matches, 2)
|
||||
assert_eq(config.world_hash_every, 300)
|
||||
assert_eq(config.to_dictionary()["matches"], 2)
|
||||
assert_false(_parse(["--server", "--world-hash-every=300"]).is_valid(), "hashes are only logged when listening")
|
||||
assert_false(_parse(["--server", "--matches=-1"]).is_valid())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user