interactive shell timeout enhancements

This commit is contained in:
sqshq 2019-06-21 00:32:02 -04:00
parent 4dbe2be260
commit fd86661ed2
3 changed files with 10 additions and 8 deletions

View File

@ -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
}

View File

@ -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
}()

View File

@ -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()
}
}