forked from samuel/go-zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
conn_test.go
57 lines (47 loc) · 1.02 KB
/
conn_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package zk
import (
"io/ioutil"
"testing"
"time"
)
func TestRecurringReAuthHang(t *testing.T) {
t.Skip("Race condition in test")
sessionTimeout := 2 * time.Second
finish := make(chan struct{})
defer close(finish)
go func() {
select {
case <-finish:
return
case <-time.After(5 * sessionTimeout):
panic("expected not hang")
}
}()
zkC, err := StartTestCluster(t, 2, ioutil.Discard, ioutil.Discard)
if err != nil {
panic(err)
}
defer zkC.Stop()
conn, evtC, err := zkC.ConnectAll()
if err != nil {
panic(err)
}
for conn.State() != StateHasSession {
time.Sleep(50 * time.Millisecond)
}
go func() {
for range evtC {
}
}()
// Add auth.
conn.AddAuth("digest", []byte("test:test"))
currentServer := conn.Server()
conn.debugCloseRecvLoop = true
conn.debugReauthDone = make(chan struct{})
zkC.StopServer(currentServer)
// wait connect to new zookeeper.
for conn.Server() == currentServer && conn.State() != StateHasSession {
time.Sleep(100 * time.Millisecond)
}
<-conn.debugReauthDone
}