testservers: return Run method errors correctly

pull/564/head
Dr. Stefan Schimanski 2018-10-30 14:05:28 +01:00
parent a13599be7e
commit 4860f8732a
4 changed files with 32 additions and 4 deletions

View File

@ -113,9 +113,10 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
return result, fmt.Errorf("failed to create config from options: %v", err)
}
errCh := make(chan error)
go func(stopCh <-chan struct{}) {
if err := app.Run(config.Complete(), stopCh); err != nil {
t.Errorf("cloud-apiserver failed run: %v", err)
errCh <- err
}
}(stopCh)
@ -125,6 +126,12 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
return result, fmt.Errorf("failed to create a client: %v", err)
}
err = wait.Poll(100*time.Millisecond, 30*time.Second, func() (bool, error) {
select {
case err := <-errCh:
return false, err
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
status := 0
result.StatusCode(&status)

View File

@ -145,9 +145,10 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
if err != nil {
return result, fmt.Errorf("failed to create server chain: %v", err)
}
errCh := make(chan error)
go func(stopCh <-chan struct{}) {
if err := server.PrepareRun().Run(stopCh); err != nil {
t.Errorf("kube-apiserver failed run: %v", err)
errCh <- err
}
}(stopCh)
@ -158,6 +159,12 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
return result, fmt.Errorf("failed to create a client: %v", err)
}
err = wait.Poll(100*time.Millisecond, 30*time.Second, func() (bool, error) {
select {
case err := <-errCh:
return false, err
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
status := 0
result.StatusCode(&status)

View File

@ -114,9 +114,10 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
return result, fmt.Errorf("failed to create config from options: %v", err)
}
errCh := make(chan error)
go func(stopCh <-chan struct{}) {
if err := app.Run(config.Complete(), stopCh); err != nil {
t.Errorf("kube-apiserver failed run: %v", err)
errCh <- err
}
}(stopCh)
@ -126,6 +127,12 @@ func StartTestServer(t Logger, customFlags []string) (result TestServer, err err
return result, fmt.Errorf("failed to create a client: %v", err)
}
err = wait.Poll(100*time.Millisecond, 30*time.Second, func() (bool, error) {
select {
case err := <-errCh:
return false, err
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
status := 0
result.StatusCode(&status)

View File

@ -150,9 +150,10 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
return result, fmt.Errorf("failed to create server: %v", err)
}
errCh := make(chan error)
go func(stopCh <-chan struct{}) {
if err := server.GenericAPIServer.PrepareRun().Run(stopCh); err != nil {
t.Errorf("apiextensions-apiserver failed run: %v", err)
errCh <- err
}
}(stopCh)
@ -163,6 +164,12 @@ func StartTestServer(t Logger, instanceOptions *TestServerInstanceOptions, custo
return result, fmt.Errorf("failed to create a client: %v", err)
}
err = wait.Poll(100*time.Millisecond, 30*time.Second, func() (bool, error) {
select {
case err := <-errCh:
return false, err
default:
}
result := client.CoreV1().RESTClient().Get().AbsPath("/healthz").Do()
status := 0
result.StatusCode(&status)