--- commandconn: fix race on `Close()` During normal operation, if a `Read()` or `Write()` call results in an EOF, we call `onEOF()` to handle the terminating command, and store it's exit value. However, if a Read/Write call was blocked while `Close()` is called the in/out pipes are immediately closed which causes an EOF to be returned. Here, we shouldn't call `onEOF()`, since the reason why we got an EOF is because we're already terminating the connection. This also prevents a race between two calls to the commands `Wait()`, in the `Close()` call and `onEOF()` --- Add CLI init timeout to SSH connections --- connhelper: add 30s ssh default dialer timeout (same as non-ssh dialer) Signed-off-by: Laura Brehm <laurabrehm@hey.com>
32 lines
581 B
Go
32 lines
581 B
Go
package connhelper
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestSSHFlags(t *testing.T) {
|
|
testCases := []struct {
|
|
in []string
|
|
out []string
|
|
}{
|
|
{
|
|
in: []string{},
|
|
out: []string{"-o ConnectTimeout=30"},
|
|
},
|
|
{
|
|
in: []string{"option", "-o anotherOption"},
|
|
out: []string{"option", "-o anotherOption", "-o ConnectTimeout=30"},
|
|
},
|
|
{
|
|
in: []string{"-o ConnectTimeout=5", "anotherOption"},
|
|
out: []string{"-o ConnectTimeout=5", "anotherOption"},
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
assert.DeepEqual(t, addSSHTimeout(tc.in), tc.out)
|
|
}
|
|
}
|