| 212 | } |
| 213 | |
| 214 | func (sc *ServerContext) WaitForRESTAPIs(ctx context.Context) error { |
| 215 | timeout := 30 * time.Second |
| 216 | interval := time.Millisecond * 100 |
| 217 | numAttempts := int(timeout / interval) |
| 218 | ctx, cancelFn := context.WithTimeout(ctx, timeout) |
| 219 | defer cancelFn() |
| 220 | err, _ := base.RetryLoop(ctx, "Wait for REST APIs", func() (shouldRetry bool, err error, value interface{}) { |
| 221 | sc._httpServersLock.RLock() |
| 222 | defer sc._httpServersLock.RUnlock() |
| 223 | if len(sc._httpServers) == len(allServers) { |
| 224 | return false, nil, nil |
| 225 | } |
| 226 | return true, nil, nil |
| 227 | }, base.CreateSleeperFunc(numAttempts, int(interval.Milliseconds()))) |
| 228 | return err |
| 229 | } |
| 230 | |
| 231 | // getServerAddr returns the address as assigned by the listener. This will return an addressable address, whereas ":0" is a valid value to pass to server. |
| 232 | func (sc *ServerContext) getServerAddr(s serverType) (string, error) { |