Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zk wait until StateHasSession #210

Open
wants to merge 1 commit into
base: v18.0.8-shopify-1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -406,7 +406,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
16 changes: 16 additions & 0 deletions go/vt/topo/zk2topo/zk_conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,19 @@ func TestZkConnClosedOnDisconnect(t *testing.T) {

require.Equal(t, zk.StateDisconnected, oldConn.State(), "Connection is not in disconnected state")
}

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())
}
}
Loading