Skip to content

Commit dbfeec1

Browse files
committed
wait until StateHasSession
1 parent d3ff598 commit dbfeec1

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

go/vt/topo/zk2topo/zk_conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func dialZk(ctx context.Context, addr string) (*zk.Conn, <-chan zk.Event, error)
409409
return nil, nil, ctx.Err()
410410
case event := <-session:
411411
switch event.State {
412-
case zk.StateConnected:
412+
case zk.StateHasSession:
413413
// success
414414
return zconn, session, nil
415415

go/vt/topo/zk2topo/zk_conn_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package zk2topo
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
"github.com/z-division/go-zookeeper/zk"
8+
"vitess.io/vitess/go/testfiles"
9+
"vitess.io/vitess/go/vt/zkctl"
10+
)
11+
12+
func TestDialWaitsForSession(t *testing.T) {
13+
zkd, serverAddr := zkctl.StartLocalZk(testfiles.GoVtTopoZk2topoZkID, testfiles.GoVtTopoZk2topoPort)
14+
defer zkd.Teardown()
15+
16+
conn, _, err := dialZk(context.Background(), serverAddr)
17+
if err != nil {
18+
t.Fatalf("dialZk failed: %v", err)
19+
}
20+
21+
defer conn.Close()
22+
23+
if conn.State() != zk.StateHasSession {
24+
t.Fatalf("zk connection not in StateHasSession: %v", conn.State())
25+
}
26+
}

0 commit comments

Comments
 (0)