interactive shell timeout enhancements
This commit is contained in:
parent
4dbe2be260
commit
fd86661ed2
|
@ -28,6 +28,7 @@ type PtyInteractiveShell struct {
|
||||||
file io.WriteCloser
|
file io.WriteCloser
|
||||||
ch chan string
|
ch chan string
|
||||||
errCount int
|
errCount int
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PtyInteractiveShell) init() error {
|
func (s *PtyInteractiveShell) init() error {
|
||||||
|
@ -119,13 +120,11 @@ await:
|
||||||
|
|
||||||
func (s *PtyInteractiveShell) getAwaitTimeout() time.Duration {
|
func (s *PtyInteractiveShell) getAwaitTimeout() time.Duration {
|
||||||
|
|
||||||
timeout := time.Duration(s.item.rateMs) * time.Millisecond
|
if s.timeout > maxAwaitTimeout {
|
||||||
|
|
||||||
if timeout > maxAwaitTimeout {
|
|
||||||
return maxAwaitTimeout
|
return maxAwaitTimeout
|
||||||
} else if timeout < minAwaitTimeout {
|
} else if s.timeout < minAwaitTimeout {
|
||||||
return minAwaitTimeout
|
return minAwaitTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
return timeout
|
return s.timeout
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ type BasicInteractiveShell struct {
|
||||||
stdin io.WriteCloser
|
stdin io.WriteCloser
|
||||||
cmd *exec.Cmd
|
cmd *exec.Cmd
|
||||||
errCount int
|
errCount int
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *BasicInteractiveShell) init() error {
|
func (s *BasicInteractiveShell) init() error {
|
||||||
|
@ -82,7 +83,7 @@ func (s *BasicInteractiveShell) execute() (string, error) {
|
||||||
timeout := make(chan bool, 1)
|
timeout := make(chan bool, 1)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Duration(s.item.rateMs / 2))
|
time.Sleep(s.timeout)
|
||||||
timeout <- true
|
timeout <- true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/sqshq/sampler/config"
|
"github.com/sqshq/sampler/config"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const errorThreshold = 10
|
const errorThreshold = 10
|
||||||
|
@ -73,11 +74,12 @@ func (i *Item) execute(variables []string, script string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Item) initInteractiveShell(v []string) error {
|
func (i *Item) initInteractiveShell(v []string) error {
|
||||||
|
timeout := time.Duration(i.rateMs) * time.Millisecond * 3 / 4
|
||||||
if i.pty {
|
if i.pty {
|
||||||
i.ptyShell = &PtyInteractiveShell{item: i, variables: v}
|
i.ptyShell = &PtyInteractiveShell{item: i, variables: v, timeout: timeout}
|
||||||
return i.ptyShell.init()
|
return i.ptyShell.init()
|
||||||
} else {
|
} else {
|
||||||
i.basicShell = &BasicInteractiveShell{item: i, variables: v}
|
i.basicShell = &BasicInteractiveShell{item: i, variables: v, timeout: timeout}
|
||||||
return i.basicShell.init()
|
return i.basicShell.init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue