(fn func() error, timeout time.Duration)
| 269 | } |
| 270 | |
| 271 | func eventually(fn func() error, timeout time.Duration) error { |
| 272 | errCh := make(chan error, 1) |
| 273 | done := make(chan struct{}) |
| 274 | exit := make(chan struct{}) |
| 275 | |
| 276 | go func() { |
| 277 | for { |
| 278 | err := fn() |
| 279 | if err == nil { |
| 280 | close(done) |
| 281 | return |
| 282 | } |
| 283 | |
| 284 | select { |
| 285 | case errCh <- err: |
| 286 | default: |
| 287 | } |
| 288 | |
| 289 | select { |
| 290 | case <-exit: |
| 291 | return |
| 292 | case <-time.After(timeout / 100): |
| 293 | } |
| 294 | } |
| 295 | }() |
| 296 | |
| 297 | select { |
| 298 | case <-done: |
| 299 | return nil |
| 300 | case <-time.After(timeout): |
| 301 | close(exit) |
| 302 | select { |
| 303 | case err := <-errCh: |
| 304 | return err |
| 305 | default: |
| 306 | return fmt.Errorf("timeout after %s without an error", timeout) |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | func connectTo(port string) (*redis.Client, error) { |
| 312 | client := redis.NewClient(&redis.Options{ |
no outgoing calls
no test coverage detected