waitForAlphaReady waits for a specific alpha to be ready after startup
(t *testing.T, cluster *dgraphtest.LocalCluster, alphaID int, timeout time.Duration)
| 503 | |
| 504 | // waitForAlphaReady waits for a specific alpha to be ready after startup |
| 505 | func waitForAlphaReady(t *testing.T, cluster *dgraphtest.LocalCluster, alphaID int, timeout time.Duration) error { |
| 506 | deadline := time.Now().Add(timeout) |
| 507 | retryDelay := 500 * time.Millisecond |
| 508 | |
| 509 | for time.Now().Before(deadline) { |
| 510 | gc, cleanup, err := cluster.AlphaClient(alphaID) |
| 511 | if err != nil { |
| 512 | t.Logf("Alpha %d not ready yet: %v, retrying in %v", alphaID, err, retryDelay) |
| 513 | time.Sleep(retryDelay) |
| 514 | retryDelay = min(retryDelay*2, 3*time.Second) |
| 515 | continue |
| 516 | } |
| 517 | |
| 518 | _, queryErr := gc.Query("schema{}") |
| 519 | cleanup() |
| 520 | |
| 521 | if queryErr != nil { |
| 522 | t.Logf("Alpha %d query failed: %v, retrying in %v", alphaID, queryErr, retryDelay) |
| 523 | time.Sleep(retryDelay) |
| 524 | retryDelay = min(retryDelay*2, 3*time.Second) |
| 525 | continue |
| 526 | } |
| 527 | |
| 528 | t.Logf("Alpha %d is ready", alphaID) |
| 529 | return nil |
| 530 | } |
| 531 | |
| 532 | return fmt.Errorf("alpha %d not ready within %v timeout", alphaID, timeout) |
| 533 | } |
| 534 | |
| 535 | // retryHealthCheck performs health check with retry logic |
| 536 | func retryHealthCheck(t *testing.T, cluster *dgraphtest.LocalCluster, timeout time.Duration) error { |
no test coverage detected