F6: Headless server entry point and smoke test
`tools/godot.sh -- --server` runs a headless dedicated server with --seed, --port, --players, --bots, --ticks, --unthrottled and --log-every. ServerLoop drives the simulation and times every tick without a scene tree, so tests run it directly. A placeholder WanderBot gives smoke runs realistic load until the v0.4 bots land. Logs are JSON lines that all carry the seed. An ErrorCounter logger makes any engine or script error exit 1; a bad command line exits 2. `make smoke` (now part of `make check`) runs 1,000 ticks with 24 bots, prints min/mean/p50/p95/p99/max tick time against the 12 ms budget, reruns to confirm the state hash reproduces, and proves a deliberate script error and a bad config both exit non-zero. Closes #6 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
extends TestCase
|
||||
|
||||
|
||||
func _parse(args: Array[String]) -> ServerConfig:
|
||||
return ServerConfig.parse(PackedStringArray(args))
|
||||
|
||||
|
||||
func test_without_server_flag_nothing_is_parsed() -> void:
|
||||
var config: ServerConfig = _parse(["--seed=5", "--bots=3"])
|
||||
assert_false(config.server)
|
||||
assert_eq(config.bots, 0)
|
||||
assert_true(config.is_valid())
|
||||
|
||||
|
||||
func test_defaults() -> void:
|
||||
var config: ServerConfig = _parse(["--server"])
|
||||
assert_true(config.server)
|
||||
assert_true(config.is_valid())
|
||||
assert_false(config.has_seed)
|
||||
assert_eq(config.port, ServerConfig.DEFAULT_PORT)
|
||||
assert_eq(config.ticks, 0)
|
||||
assert_false(config.unthrottled)
|
||||
|
||||
|
||||
func test_all_options() -> void:
|
||||
var config: ServerConfig = _parse([
|
||||
"--path", "/ignored", "--server", "--seed=-17", "--port=4000", "--players=3",
|
||||
"--bots=20", "--ticks=900", "--unthrottled", "--log-every=30",
|
||||
])
|
||||
assert_true(config.is_valid(), str(config.errors))
|
||||
assert_true(config.has_seed)
|
||||
assert_eq(config.match_seed, -17)
|
||||
assert_eq(config.port, 4000)
|
||||
assert_eq(config.players, 3)
|
||||
assert_eq(config.bots, 20)
|
||||
assert_eq(config.ticks, 900)
|
||||
assert_true(config.unthrottled)
|
||||
assert_eq(config.log_every, 30)
|
||||
|
||||
|
||||
func test_large_seed_round_trips() -> void:
|
||||
var config: ServerConfig = _parse(["--server", "--seed=9223372036854775807"])
|
||||
assert_eq(config.match_seed, 9223372036854775807)
|
||||
assert_eq(config.to_dictionary()["seed"], 9223372036854775807)
|
||||
|
||||
|
||||
func test_unknown_argument_is_an_error() -> void:
|
||||
var config: ServerConfig = _parse(["--server", "--bot=3"])
|
||||
assert_false(config.is_valid())
|
||||
assert_true(config.errors[0].contains("--bot=3"))
|
||||
|
||||
|
||||
func test_non_numeric_value_is_an_error() -> void:
|
||||
var config: ServerConfig = _parse(["--server", "--seed=abc"])
|
||||
assert_false(config.is_valid())
|
||||
assert_false(config.has_seed)
|
||||
|
||||
|
||||
func test_ranges_are_checked() -> void:
|
||||
assert_false(_parse(["--server", "--port=0"]).is_valid())
|
||||
assert_false(_parse(["--server", "--port=70000"]).is_valid())
|
||||
assert_false(_parse(["--server", "--bots=-1"]).is_valid())
|
||||
assert_false(_parse(["--server", "--ticks=-1"]).is_valid())
|
||||
assert_false(_parse(["--server", "--fault=meteor"]).is_valid())
|
||||
var too_many: String = "--bots=%d" % (Tuning.SOLO_PLAYERS + 1)
|
||||
assert_false(_parse(["--server", too_many]).is_valid())
|
||||
var full: Array[String] = ["--server", "--players=4", "--bots=%d" % (Tuning.SOLO_PLAYERS - 4)]
|
||||
assert_true(_parse(full).is_valid())
|
||||
@@ -0,0 +1 @@
|
||||
uid://cmngmhd4ivq50
|
||||
@@ -0,0 +1,59 @@
|
||||
extends TestCase
|
||||
|
||||
|
||||
func _run(match_seed: int, players: int, bots: int, ticks: int) -> ServerLoop:
|
||||
var loop: ServerLoop = ServerLoop.new(match_seed, players, bots)
|
||||
for _index: int in ticks:
|
||||
loop.run_tick()
|
||||
return loop
|
||||
|
||||
|
||||
func test_creates_players_then_bots() -> void:
|
||||
var loop: ServerLoop = ServerLoop.new(1, 2, 3)
|
||||
assert_eq(loop.sim.entities.count(), 5)
|
||||
assert_eq(loop.player_ids, [1, 2, 3, 4, 5] as Array[int])
|
||||
assert_eq(loop.bots.size(), 3)
|
||||
assert_eq(loop.bots[0].player_id, 3)
|
||||
|
||||
|
||||
func test_records_one_timing_sample_per_tick() -> void:
|
||||
var loop: ServerLoop = _run(7, 0, 4, 120)
|
||||
assert_eq(loop.sim.tick, 120)
|
||||
var stats: Dictionary = loop.timing_stats()
|
||||
assert_eq(stats["ticks"], 120)
|
||||
assert_true(stats["min_us"] <= stats["p50_us"])
|
||||
assert_true(stats["p50_us"] <= stats["p95_us"])
|
||||
assert_true(stats["p95_us"] <= stats["p99_us"])
|
||||
assert_true(stats["p99_us"] <= stats["max_us"])
|
||||
assert_eq(stats["budget_us"], ServerLoop.TICK_BUDGET_USEC)
|
||||
|
||||
|
||||
func test_empty_stats() -> void:
|
||||
assert_eq(ServerLoop.new(1, 0, 0).timing_stats(), {"ticks": 0})
|
||||
|
||||
|
||||
func test_percentile_uses_nearest_rank() -> void:
|
||||
var values: PackedInt64Array = PackedInt64Array(range(1, 101))
|
||||
assert_eq(ServerLoop._percentile(values, 0.5), 50)
|
||||
assert_eq(ServerLoop._percentile(values, 0.95), 95)
|
||||
assert_eq(ServerLoop._percentile(values, 1.0), 100)
|
||||
assert_eq(ServerLoop._percentile(PackedInt64Array([9]), 0.99), 9)
|
||||
|
||||
|
||||
func test_bots_move_and_humans_without_commands_stay_put() -> void:
|
||||
var loop: ServerLoop = ServerLoop.new(99, 1, 1)
|
||||
var human: SimEntity = loop.sim.entities.find(1)
|
||||
var bot: SimEntity = loop.sim.entities.find(2)
|
||||
var human_start: Vector3 = human.position
|
||||
var bot_start: Vector3 = bot.position
|
||||
for _index: int in 90:
|
||||
loop.run_tick()
|
||||
assert_eq(human.position, human_start)
|
||||
assert_true(bot.position.distance_to(bot_start) > 1.0, "the bot should have walked")
|
||||
|
||||
|
||||
func test_same_seed_gives_the_same_match() -> void:
|
||||
var first: String = _run(2026, 2, 22, 300).sim.state_hash()
|
||||
var second: String = _run(2026, 2, 22, 300).sim.state_hash()
|
||||
assert_eq(first, second)
|
||||
assert_ne(first, _run(2027, 2, 22, 300).sim.state_hash())
|
||||
@@ -0,0 +1 @@
|
||||
uid://b8lr7u4qaduqp
|
||||
Reference in New Issue
Block a user