extends TestCase ## H4: tick timing in fixed memory, and the server's launchers keeping the allocator to ## one arena so resident memory doesn't grow match after match. func test_statistics_match_a_sorted_list() -> void: var times: TickTimes = TickTimes.new() var values: PackedInt64Array = PackedInt64Array() var rng: RandomNumberGenerator = RandomNumberGenerator.new() rng.seed = 4 for index: int in 5000: var usec: int = rng.randi_range(200, 3000) if index % 500 != 0 else rng.randi_range(70000, 2000000) times.add(usec) values.append(usec) values.sort() for fraction: float in [0.0, 0.01, 0.5, 0.95, 0.99, 0.999, 1.0]: assert_eq(times.percentile(fraction), ServerLoop._percentile(values, fraction), "percentile %.3f" % fraction) var stats: Dictionary = times.stats(ServerLoop.TICK_BUDGET_USEC) assert_eq(stats["ticks"], 5000) assert_eq(stats["min_us"], values[0]) assert_eq(stats["max_us"], values[-1]) assert_eq(stats["over_budget"], 10, "the ten slow ticks") assert_eq(TickTimes.new().stats(1000), {"ticks": 0}) func test_memory_stays_fixed_past_the_slow_tick_cap() -> void: var times: TickTimes = TickTimes.new() for index: int in TickTimes.MAX_SLOW + 100: times.add(TickTimes.HISTOGRAM_USEC + index) assert_eq(times._slow.size(), TickTimes.MAX_SLOW) assert_eq(times.size(), TickTimes.MAX_SLOW + 100) assert_eq(times.percentile(1.0), TickTimes.HISTOGRAM_USEC + TickTimes.MAX_SLOW + 99, "the slowest are kept") assert_eq(times.over(12000), TickTimes.MAX_SLOW + 100) func test_server_launchers_use_one_malloc_arena() -> void: for path: String in ["res://packaging/server/tidewall-server", "res://packaging/dist/tidewall-server", "res://tools/godot.sh"]: var text: String = FileAccess.get_file_as_string(path) assert_true(text.contains('export MALLOC_ARENA_MAX="${MALLOC_ARENA_MAX:-1}"'), "%s sets MALLOC_ARENA_MAX" % path)