perf_bench: the readiness gate only with a chunk target; a test for the quiet start
Without min_chunks (the old call) wait_loaded behaves as before, which tests/test_perf_bench.py's old-builds case relies on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,7 +50,7 @@ if __name__ == "__main__":
|
||||
class WaitLoadedTests(unittest.TestCase):
|
||||
"""wait_loaded on a scripted game with a fake clock: one status per 50 ms poll."""
|
||||
|
||||
def run_script(self, statuses):
|
||||
def run_script(self, statuses, min_chunks=0):
|
||||
import tools.perf_bench as pb
|
||||
clock = [0.0]
|
||||
it = iter(statuses)
|
||||
@@ -62,7 +62,7 @@ class WaitLoadedTests(unittest.TestCase):
|
||||
pb.time.time = lambda: clock[0]
|
||||
pb.time.sleep = lambda s: clock.__setitem__(0, clock[0] + s)
|
||||
try:
|
||||
return pb.wait_loaded(control, lambda p: True, 60)
|
||||
return pb.wait_loaded(control, lambda p: True, 60, min_chunks)
|
||||
finally:
|
||||
pb.time.time, pb.time.sleep = real_time, real_sleep
|
||||
|
||||
@@ -86,3 +86,15 @@ class WaitLoadedTests(unittest.TestCase):
|
||||
busy = [self.status(901, 1000 * i) for i in range(20)]
|
||||
quiet = [self.status(901, 20000 + i) for i in range(40)]
|
||||
self.assertAlmostEqual(self.run_script(busy + quiet), 1.0, places=6)
|
||||
|
||||
def test_a_quiet_start_is_not_a_load(self):
|
||||
# Right after a teleport Horizon reports steady counts and nothing queued for 1.5 s before it loads:
|
||||
# with a target the clock runs on until the chunks are there and the meshing has gone quiet.
|
||||
idle = [self.status(3, 0, stages=0) for _ in range(30)]
|
||||
loading = [self.status(30 * (i + 1), 500 * i, stages=500) for i in range(20)]
|
||||
tail = [self.status(600, 10000, stages=0) for _ in range(60)]
|
||||
took = self.run_script(idle + loading + tail, min_chunks=500)
|
||||
self.assertGreater(took, 2.4)
|
||||
self.assertLess(took, 4.0)
|
||||
# Without one (the old call), the quiet start ends the wait at once.
|
||||
self.assertLess(self.run_script(idle + loading + tail), 1.6)
|
||||
|
||||
+1
-1
@@ -342,7 +342,7 @@ def wait_loaded(control, near, limit, min_chunks=0):
|
||||
counts = (s["chunks"], s["generated_chunks"])
|
||||
first = first or counts
|
||||
moved = moved or counts != first or (s["chunks"] >= min_chunks > 0 and now - began > 5)
|
||||
if not moved or s["chunks"] < min_chunks:
|
||||
if min_chunks and (not moved or s["chunks"] < min_chunks):
|
||||
last, changed, previous, meshing = None, now, None, now
|
||||
time.sleep(0.05)
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user