mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Retry conntrack, after a short delay, in a loop.
This commit is contained in:
@@ -4,31 +4,39 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/weaveworks/scope/common/exec"
|
||||
)
|
||||
|
||||
type mockCmd struct {
|
||||
io.ReadCloser
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
type blockingReader struct {
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
// NewMockCmdString creates a new mock Cmd which has s on its stdout pipe
|
||||
func NewMockCmdString(s string) exec.Cmd {
|
||||
return &mockCmd{
|
||||
struct {
|
||||
ReadCloser: struct {
|
||||
io.Reader
|
||||
io.Closer
|
||||
}{
|
||||
bytes.NewBufferString(s),
|
||||
ioutil.NopCloser(nil),
|
||||
},
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
// NewMockCmd creates a new mock Cmd with rc as its stdout pipe
|
||||
func NewMockCmd(rc io.ReadCloser) exec.Cmd {
|
||||
return &mockCmd{rc}
|
||||
return &mockCmd{
|
||||
ReadCloser: rc,
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *mockCmd) Start() error {
|
||||
@@ -43,6 +51,21 @@ func (c *mockCmd) StdoutPipe() (io.ReadCloser, error) {
|
||||
return c.ReadCloser, nil
|
||||
}
|
||||
|
||||
func (c *mockCmd) Process() *os.Process {
|
||||
func (c *mockCmd) StderrPipe() (io.ReadCloser, error) {
|
||||
return &blockingReader{c.quit}, nil
|
||||
}
|
||||
|
||||
func (c *mockCmd) Kill() error {
|
||||
close(c.quit)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *blockingReader) Read(p []byte) (n int, err error) {
|
||||
<-b.quit
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (b *blockingReader) Close() error {
|
||||
<-b.quit
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user