Skip to content

Commit 8fc787b

Browse files
author
Priya Wadhwa
committed
Fail fast if waiting for SSH to be available
Integration tests were running long because we'd wait up to 22 minutes for SSH to succeed while creating the host. This commit introduces a two minute timer on creating the host. On my Macbook Pro with the docker driver, creating the host takes 5 seconds, so 2 minutes should be more than enough time. Refer to #6608
1 parent 3bb1a57 commit 8fc787b

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

pkg/minikube/cluster/start.go

+29-4
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
134134

135135
cstart := time.Now()
136136
glog.Infof("libmachine.API.Create for %q (driver=%q)", cfg.Name, cfg.VMDriver)
137-
if err := api.Create(h); err != nil {
138-
// Wait for all the logs to reach the client
139-
time.Sleep(2 * time.Second)
140-
return nil, errors.Wrap(err, "create")
137+
// Allow two minutes to create host before failing fast
138+
if err := timedCreateHost(h, api, 2*time.Minute); err != nil {
139+
return nil, errors.Wrap(err, "creating host")
141140
}
142141
glog.Infof("libmachine.API.Create for %q took %s", cfg.Name, time.Since(cstart))
143142

@@ -151,6 +150,32 @@ func createHost(api libmachine.API, cfg config.MachineConfig) (*host.Host, error
151150
return h, nil
152151
}
153152

153+
func timedCreateHost(h *host.Host, api libmachine.API, t time.Duration) error {
154+
timeout := make(chan bool, 1)
155+
go func() {
156+
time.Sleep(t)
157+
timeout <- true
158+
}()
159+
160+
createFinished := make(chan bool, 1)
161+
var err error
162+
go func() {
163+
err = api.Create(h)
164+
createFinished <- true
165+
}()
166+
167+
select {
168+
case <-createFinished:
169+
if err != nil {
170+
time.Sleep(2 * time.Second)
171+
return errors.Wrap(err, "create")
172+
}
173+
return nil
174+
case <-timeout:
175+
return fmt.Errorf("create host timed out in %f seconds", t.Seconds())
176+
}
177+
}
178+
154179
// postStart are functions shared between startHost and fixHost
155180
func postStartSetup(h *host.Host, mc config.MachineConfig) error {
156181
glog.Infof("post-start starting for %q (driver=%q)", h.Name, h.DriverName)

0 commit comments

Comments
 (0)