Skip to content

Commit

Permalink
test: retry incase of connection error
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Oct 3, 2023
1 parent 2f1fc13 commit 377a988
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions go/vt/topo/zk2topo/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"fmt"
"path"
"testing"
"time"

"github.com/stretchr/testify/require"

"vitess.io/vitess/go/testfiles"
"vitess.io/vitess/go/vt/topo"
Expand Down Expand Up @@ -51,14 +54,25 @@ func TestZk2Topo(t *testing.T) {
// Note we exercise the observer feature here by passing in
// the same server twice, with a "|" separator.
ts, err := topo.OpenServer("zk2", serverAddr+"|"+serverAddr, globalRoot)
if err != nil {
t.Fatalf("OpenServer() failed: %v", err)
}
if err := ts.CreateCellInfo(context.Background(), test.LocalCellName, &topodatapb.CellInfo{
ServerAddress: serverAddr,
Root: cellRoot,
}); err != nil {
t.Fatalf("CreateCellInfo() failed: %v", err)
require.NoError(t, err, "OpenServer() failed")
// We retry creating the cell info until we no longer get a connection error.
timeout := time.After(15 * time.Second)
for {
err = ts.CreateCellInfo(context.Background(), test.LocalCellName, &topodatapb.CellInfo{
ServerAddress: serverAddr,
Root: cellRoot,
})
if err == nil {
break
}
select {
case <-timeout:
t.Fatalf("Timedout creating cell info - %v", err)
return nil
default:
require.ErrorContainsf(t, err, "could not connect to a server", "Received an error that isn't a connection error")
time.Sleep(1 * time.Second)
}
}

return ts
Expand Down

0 comments on commit 377a988

Please sign in to comment.