@@ -18,6 +18,7 @@ import (
1818 "path/filepath"
1919 "strings"
2020 "testing"
21+ "time"
2122
2223 "github.com/stretchr/testify/require"
2324 "google.golang.org/grpc"
@@ -41,15 +42,21 @@ var (
4142func TestBackupHAClust (t * testing.T ) {
4243
4344 backupRestoreTest (t , "alpha1_backup_clust_ha" , "zero1_backup_clust_ha" ,
44- testutil .GetSockAddr (), testutil .GetSockAddrAlpha4Http (),
45- testutil .GetSockAddrZeroHttp (), backupDstHA , testutil .GetSockAddrHttp ())
45+ testutil .ContainerAddr ("alpha1_backup_clust_ha" , 9080 ),
46+ testutil .ContainerAddr ("alpha4_restore_clust_ha" , 8080 ),
47+ testutil .ContainerAddr ("zero1_backup_clust_ha" , 6080 ),
48+ backupDstHA ,
49+ testutil .ContainerAddr ("alpha1_backup_clust_ha" , 8080 ))
4650}
4751
4852func TestBackupNonHAClust (t * testing.T ) {
4953
5054 backupRestoreTest (t , "alpha7_backup_clust_non_ha" , "zero7_backup_clust_non_ha" ,
51- testutil .GetSockAddrAlpha7 (), testutil .GetSockAddrAlpha8Http (),
52- testutil .GetSockAddrZero7Http (), backupDstNonHA , testutil .GetSockAddrAlpha7Http ())
55+ testutil .ContainerAddr ("alpha7_backup_clust_non_ha" , 9080 ),
56+ testutil .ContainerAddr ("alpha8_restore_clust_non_ha" , 8080 ),
57+ testutil .ContainerAddr ("zero7_backup_clust_non_ha" , 6080 ),
58+ backupDstNonHA ,
59+ testutil .ContainerAddr ("alpha7_backup_clust_non_ha" , 8080 ))
5360}
5461
5562func backupRestoreTest (t * testing.T , backupAlphaName string , backupZeroName string ,
@@ -65,15 +72,28 @@ func backupRestoreTest(t *testing.T, backupAlphaName string, backupZeroName stri
6572 backupZero := testutil.ContainerInstance {Name : backupZeroName , Prefix : testutil .DockerPrefix }
6673 require .NoError (t , backupZero .BestEffortWaitForHealthy (6080 ))
6774
68- conn , err := grpc .NewClient (backupAlphaSocketAddr , grpc .WithTransportCredentials (insecure .NewCredentials ()))
69- require .NoError (t , err )
70- dg := dgo .NewDgraphClient (api .NewDgraphClient (conn ))
75+ var dg * dgo.Dgraph
76+ var err error
7177 ctx := context .Background ()
7278
7379 // Wait for gRPC connection to be ready with retries
7480 t .Log ("Waiting for gRPC connection to be ready..." )
75- _ , err = testutil .RetryQuery (dg , `{ health { status } }` )
76- require .NoError (t , err )
81+ for i := 0 ; i < 30 ; i ++ {
82+ conn , connErr := grpc .NewClient (backupAlphaSocketAddr , grpc .WithTransportCredentials (insecure .NewCredentials ()))
83+ if connErr != nil {
84+ t .Logf ("Failed to create gRPC client (attempt %d/30): %v" , i + 1 , connErr )
85+ time .Sleep (time .Second )
86+ continue
87+ }
88+ dg = dgo .NewDgraphClient (api .NewDgraphClient (conn ))
89+ _ , err = testutil .RetryQuery (dg , `{ health { status } }` )
90+ if err == nil {
91+ break
92+ }
93+ t .Logf ("Health query failed (attempt %d/30): %v" , i + 1 , err )
94+ time .Sleep (time .Second )
95+ }
96+ require .NoError (t , err , "Failed to connect to gRPC after 30 attempts" )
7797
7898 require .NoError (t , dg .Alter (ctx , & api.Operation {DropAll : true }))
7999 // Add schema and types.
0 commit comments