increase test-connection timeout and invoke in goroutines

This commit is contained in:
Drew Weymouth
2023-02-18 09:30:16 -08:00
parent 04461bf9e2
commit 2db035b2bd
4 changed files with 114 additions and 56 deletions
+4 -2
View File
@@ -37,15 +37,17 @@ func (s *ServerManager) ConnectToServer(conf *ServerConfig, password string) err
return nil
}
func (s *ServerManager) TestConnectionAndAuth(hostname, username, password string) error {
func (s *ServerManager) TestConnectionAndAuth(hostname, username, password string, timeout time.Duration) error {
err := ErrUnreachable
done := make(chan bool)
go func() {
_, err = s.testConnectionAndCreateClient(hostname, username, password)
close(done)
}()
t := time.NewTimer(timeout)
defer t.Stop()
select {
case <-time.After(200 * time.Millisecond):
case <-t.C:
return err
case <-done:
return err