From 0f45ad51522ee6f9b9b137ee5fc814004f991d01 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 31 Dec 2024 01:22:05 +0530 Subject: [PATCH] refactor: streamline ShellExecutable.Start method to support dynamic read timeout --- internal/shell_executable/shell_executable.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/shell_executable/shell_executable.go b/internal/shell_executable/shell_executable.go index b77fcd9..4a0d910 100644 --- a/internal/shell_executable/shell_executable.go +++ b/internal/shell_executable/shell_executable.go @@ -65,6 +65,11 @@ func (b *ShellExecutable) Start(args ...string) error { b.Setenv("PS1", utils.PROMPT) // b.Setenv("TERM", "dumb") // test_all_success works without this too, do we need it? + readTimeout := 2000 * time.Millisecond + if len(args) > 0 && args[0] == "setLongerReadTimeout" { + readTimeout = 5000 * time.Millisecond + args = args[1:] + } cmd := exec.Command(b.executable.Path, args...) cmd.Env = b.env.Sorted() @@ -77,12 +82,6 @@ func (b *ShellExecutable) Start(args ...string) error { b.cmd = cmd b.pty = pty b.vt = virtual_terminal.NewStandardVT() - - readTimeout := 2000 * time.Millisecond - if len(args) > 0 && args[0] == "setLongerReadTimeout" { - readTimeout = 5000 * time.Millisecond - args = args[1:] - } b.ptyReader = condition_reader.NewConditionReader(io.TeeReader(b.pty, b.vt), readTimeout) return nil