diff --git a/tools/test_server_ops_feedback_parity.py b/tools/test_server_ops_feedback_parity.py index f7b7a0e73..91854fac6 100644 --- a/tools/test_server_ops_feedback_parity.py +++ b/tools/test_server_ops_feedback_parity.py @@ -19,17 +19,16 @@ import platform import shutil import subprocess import sys -import time try: from . import lab, test_rust_parity as base - from .test_dedicated_server_parity import Server - from .test_locator_bar_parity import generate_world, server_dir + from .test_dedicated_server_parity import Server, game_time + from .test_locator_bar_parity import Client, generate_world, server_dir except ImportError: import lab import test_rust_parity as base - from test_dedicated_server_parity import Server - from test_locator_bar_parity import generate_world, server_dir + from test_dedicated_server_parity import Server, game_time + from test_locator_bar_parity import Client, generate_world, server_dir NAME = 'server-ops-feedback-parity' # (label, what the console does, what the players do). @@ -53,7 +52,11 @@ QUIET = [ ('alice', [], ['cmd Alice time set 3000']), ] CASES = {'broadcast': ({}, BROADCAST), 'quiet': ({'broadcast-console-to-ops': 'false'}, QUIET)} -STEP_SECONDS = 2.0 +STEP_TICKS = 40 +# A step ends by the server's clock (Client.wait): after a round trip of Alice's (Bob is deopped for a while, so +# his is not used). While send_command_feedback is off a command has no reply for her, so those steps wait for +# the ticks alone. +NO_SYNC = {'feedback-off', 'console-feedback-off'} # Steps whose reply can take longer than a step: the next step waits for this console line first. A loaded machine # took 2 s to save vanilla's world, and the transcript ended before "Saved the game". WAIT_FOR = {'console-save': r'System chat: Saved the game'} @@ -72,33 +75,26 @@ def run_side(label, case, server_command, client_command, build, world): try: server.wait_for(r'Done \(') with (build / f'{label}-{case}-client.log').open('w') as log: - client = subprocess.Popen([*map(str, client_command), '127.0.0.1', str(port), str(out)], - cwd=lab.ROOT, stdin=subprocess.PIPE, stdout=log, stderr=subprocess.STDOUT, - text=True) - - def tell(line): - client.stdin.write(line + '\n') - client.stdin.flush() + client = Client(client_command, port, out, log) try: for name in ('Alice', 'Bob'): - tell(f'join {name}') + client.tell(f'join {name}') server.wait_for(rf'{name} joined the game', timeout=120) - time.sleep(STEP_SECONDS) - tell('chat on') + client.wait(server, ['Alice'], STEP_TICKS) + client.tell('chat on') for step, console, actions in script: - tell(f'step {step}') + client.tell(f'step {step}') for command in console: server.console(command) + game_time(server) # the console runs its queue in order: these commands have run for action in actions: - tell(action) + client.tell(action) if step in WAIT_FOR: server.wait_for(WAIT_FOR[step], timeout=120) - time.sleep(STEP_SECONDS) - tell('end') - client.wait(timeout=60) + client.wait(server, [] if step in NO_SYNC else ['Alice'], STEP_TICKS) + client.end() finally: - if client.poll() is None: - client.kill() + client.kill() finally: server.stop() if not out.exists():