fix(test_framework): pass --max-speed to Java runner and drain stdout to prevent pipe stall
- Add maxSpeed param (default true) to runBattleRunner/runBattle - Drain stdout in poll loop — Java blocked on full pipe buffer causing timeout - TestBattleRunner.java already had --max-speed; .class was stale and needed recompile Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,19 +7,20 @@ const
|
|||||||
ScriptDir = currentSourcePath().parentDir() / ".." / ".." / "tools" / "battle_runner"
|
ScriptDir = currentSourcePath().parentDir() / ".." / ".." / "tools" / "battle_runner"
|
||||||
|
|
||||||
proc runBattleRunner*(serverUrl: string, botDirs: seq[string], rounds: int,
|
proc runBattleRunner*(serverUrl: string, botDirs: seq[string], rounds: int,
|
||||||
timeout: int = 30000): string =
|
timeout: int = 30000, maxSpeed: bool = true): string =
|
||||||
## Starts TestBattleRunner as a subprocess. Returns captured stdout on success.
|
## Starts TestBattleRunner as a subprocess. Returns captured stdout on success.
|
||||||
## Raises IOError on non-zero exit or TimeoutError on timeout.
|
## Raises IOError on non-zero exit or TimeoutError on timeout.
|
||||||
let jar = getEnv("TR_BATTLE_RUNNER", DefaultRunnerJar)
|
let jar = getEnv("TR_BATTLE_RUNNER", DefaultRunnerJar)
|
||||||
let classDir = getEnv("TR_BATTLE_RUNNER_DIR", ScriptDir)
|
let classDir = getEnv("TR_BATTLE_RUNNER_DIR", ScriptDir)
|
||||||
|
|
||||||
let args = @[
|
var args = @[
|
||||||
"-cp", classDir & ":" & jar,
|
"-cp", classDir & ":" & jar,
|
||||||
"TestBattleRunner",
|
"TestBattleRunner",
|
||||||
"--server-url", serverUrl,
|
"--server-url", serverUrl,
|
||||||
"--rounds", $rounds,
|
"--rounds", $rounds,
|
||||||
"--bot-dirs", botDirs.join(",")
|
"--bot-dirs", botDirs.join(",")
|
||||||
]
|
]
|
||||||
|
if maxSpeed: args.add("--max-speed")
|
||||||
|
|
||||||
let p = startProcess("java", args = args,
|
let p = startProcess("java", args = args,
|
||||||
options = {poUsePath, poStdErrToStdOut})
|
options = {poUsePath, poStdErrToStdOut})
|
||||||
@@ -29,13 +30,12 @@ proc runBattleRunner*(serverUrl: string, botDirs: seq[string], rounds: int,
|
|||||||
let deadline = epochTime() + timeout.float / 1000.0
|
let deadline = epochTime() + timeout.float / 1000.0
|
||||||
var stdout = ""
|
var stdout = ""
|
||||||
var line: string
|
var line: string
|
||||||
# ponytail: poll instead of blocking readLine; 50ms sleep is fine for battle timescales
|
|
||||||
while epochTime() < deadline:
|
while epochTime() < deadline:
|
||||||
|
# Drain stdout every iteration to prevent pipe-buffer stall
|
||||||
|
while p.outputStream.atEnd == false:
|
||||||
|
discard p.outputStream.readLine(line)
|
||||||
|
stdout.add(line & "\n")
|
||||||
if p.peekExitCode() != -1:
|
if p.peekExitCode() != -1:
|
||||||
# Process finished; drain remaining output without blocking
|
|
||||||
while p.outputStream.atEnd == false:
|
|
||||||
discard p.outputStream.readLine(line)
|
|
||||||
stdout.add(line & "\n")
|
|
||||||
break
|
break
|
||||||
sleep(50)
|
sleep(50)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user