mirror of https://github.com/docker/docs.git
Make test 10s faster
Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
parent
9e8c6b8ff0
commit
f56dab0676
|
|
@ -73,6 +73,7 @@ type Plugin struct {
|
||||||
MachineName string
|
MachineName string
|
||||||
addrCh chan string
|
addrCh chan string
|
||||||
stopCh chan bool
|
stopCh chan bool
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type Executor struct {
|
type Executor struct {
|
||||||
|
|
@ -230,13 +231,17 @@ func (lbp *Plugin) Serve() error {
|
||||||
|
|
||||||
func (lbp *Plugin) Address() (string, error) {
|
func (lbp *Plugin) Address() (string, error) {
|
||||||
if lbp.Addr == "" {
|
if lbp.Addr == "" {
|
||||||
|
if lbp.timeout == 0 {
|
||||||
|
lbp.timeout = defaultTimeout
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case lbp.Addr = <-lbp.addrCh:
|
case lbp.Addr = <-lbp.addrCh:
|
||||||
log.Debugf("Plugin server listening at address %s", lbp.Addr)
|
log.Debugf("Plugin server listening at address %s", lbp.Addr)
|
||||||
close(lbp.addrCh)
|
close(lbp.addrCh)
|
||||||
return lbp.Addr, nil
|
return lbp.Addr, nil
|
||||||
case <-time.After(defaultTimeout):
|
case <-time.After(lbp.timeout):
|
||||||
return "", fmt.Errorf("Failed to dial the plugin server in %s", defaultTimeout)
|
return "", fmt.Errorf("Failed to dial the plugin server in %s", lbp.timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return lbp.Addr, nil
|
return lbp.Addr, nil
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/docker/machine/libmachine/log"
|
"github.com/docker/machine/libmachine/log"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FakeExecutor struct {
|
type FakeExecutor struct {
|
||||||
|
|
@ -56,15 +57,16 @@ func TestLocalBinaryPluginAddressTimeout(t *testing.T) {
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
t.Skip("Skipping timeout test")
|
t.Skip("Skipping timeout test")
|
||||||
}
|
}
|
||||||
lbp := &Plugin{}
|
|
||||||
lbp.addrCh = make(chan string, 1)
|
lbp := &Plugin{
|
||||||
go func() {
|
addrCh: make(chan string, 1),
|
||||||
_, err := lbp.Address()
|
timeout: 1 * time.Second,
|
||||||
if err == nil {
|
|
||||||
t.Fatalf("Expected to get a timeout error, instead got %s", err)
|
|
||||||
}
|
}
|
||||||
}()
|
|
||||||
time.Sleep(defaultTimeout + 1)
|
addr, err := lbp.Address()
|
||||||
|
|
||||||
|
assert.Empty(t, addr)
|
||||||
|
assert.EqualError(t, err, "Failed to dial the plugin server in 1s")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLocalBinaryPluginClose(t *testing.T) {
|
func TestLocalBinaryPluginClose(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue