Skip to content

Commit

Permalink
wait until StateHasSession
Browse files Browse the repository at this point in the history
  • Loading branch information
shanth96 committed Feb 7, 2025
1 parent d3ff598 commit dbfeec1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go/vt/topo/zk2topo/zk_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func dialZk(ctx context.Context, addr string) (*zk.Conn, <-chan zk.Event, error)
return nil, nil, ctx.Err()
case event := <-session:
switch event.State {
case zk.StateConnected:
case zk.StateHasSession:
// success
return zconn, session, nil

Expand Down
26 changes: 26 additions & 0 deletions go/vt/topo/zk2topo/zk_conn_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package zk2topo

import (
"context"
"testing"

"github.com/z-division/go-zookeeper/zk"
"vitess.io/vitess/go/testfiles"
"vitess.io/vitess/go/vt/zkctl"
)

func TestDialWaitsForSession(t *testing.T) {
zkd, serverAddr := zkctl.StartLocalZk(testfiles.GoVtTopoZk2topoZkID, testfiles.GoVtTopoZk2topoPort)
defer zkd.Teardown()

conn, _, err := dialZk(context.Background(), serverAddr)
if err != nil {
t.Fatalf("dialZk failed: %v", err)
}

defer conn.Close()

if conn.State() != zk.StateHasSession {
t.Fatalf("zk connection not in StateHasSession: %v", conn.State())
}
}

0 comments on commit dbfeec1

Please sign in to comment.