MCPcopy
hub / github.com/dgraph-io/dgraph / waitForAlphaReady

Function waitForAlphaReady

dgraph/cmd/dgraphimport/import_test.go:505–533  ·  view source on GitHub ↗

waitForAlphaReady waits for a specific alpha to be ready after startup

(t *testing.T, cluster *dgraphtest.LocalCluster, alphaID int, timeout time.Duration)

Source from the content-addressed store, hash-verified

503
504// waitForAlphaReady waits for a specific alpha to be ready after startup
505func 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
536func retryHealthCheck(t *testing.T, cluster *dgraphtest.LocalCluster, timeout time.Duration) error {

Callers 1

runImportTestFunction · 0.85

Calls 6

minFunction · 0.85
cleanupFunction · 0.85
AlphaClientMethod · 0.80
AddMethod · 0.45
QueryMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected