diff --git a/data/int_pty.go b/data/int_pty.go index dd9725a..644cf10 100644 --- a/data/int_pty.go +++ b/data/int_pty.go @@ -28,6 +28,7 @@ type PtyInteractiveShell struct { file io.WriteCloser ch chan string errCount int + timeout time.Duration } func (s *PtyInteractiveShell) init() error { @@ -119,13 +120,11 @@ await: func (s *PtyInteractiveShell) getAwaitTimeout() time.Duration { - timeout := time.Duration(s.item.rateMs) * time.Millisecond - - if timeout > maxAwaitTimeout { + if s.timeout > maxAwaitTimeout { return maxAwaitTimeout - } else if timeout < minAwaitTimeout { + } else if s.timeout < minAwaitTimeout { return minAwaitTimeout } - return timeout + return s.timeout } diff --git a/data/int_shell.go b/data/int_shell.go index 70fa7dd..f42d9eb 100644 --- a/data/int_shell.go +++ b/data/int_shell.go @@ -18,6 +18,7 @@ type BasicInteractiveShell struct { stdin io.WriteCloser cmd *exec.Cmd errCount int + timeout time.Duration } func (s *BasicInteractiveShell) init() error { @@ -82,7 +83,7 @@ func (s *BasicInteractiveShell) execute() (string, error) { timeout := make(chan bool, 1) go func() { - time.Sleep(time.Duration(s.item.rateMs / 2)) + time.Sleep(s.timeout) timeout <- true }() diff --git a/data/item.go b/data/item.go index aa04f8d..25f1e32 100644 --- a/data/item.go +++ b/data/item.go @@ -5,6 +5,7 @@ import ( "github.com/sqshq/sampler/config" "os" "os/exec" + "time" ) const errorThreshold = 10 @@ -73,11 +74,12 @@ func (i *Item) execute(variables []string, script string) (string, error) { } func (i *Item) initInteractiveShell(v []string) error { + timeout := time.Duration(i.rateMs) * time.Millisecond * 3 / 4 if i.pty { - i.ptyShell = &PtyInteractiveShell{item: i, variables: v} + i.ptyShell = &PtyInteractiveShell{item: i, variables: v, timeout: timeout} return i.ptyShell.init() } else { - i.basicShell = &BasicInteractiveShell{item: i, variables: v} + i.basicShell = &BasicInteractiveShell{item: i, variables: v, timeout: timeout} return i.basicShell.init() } }