-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzkclient_test.go
63 lines (50 loc) · 1000 Bytes
/
zkclient_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
58
59
60
61
62
63
// Copyright 2018-2019 The vogo Authors. All rights reserved.
// author: wongoo
// since: 2019/10/12
//
package zkclient
import (
"sync"
"sync/atomic"
"testing"
"time"
"github.com/vogo/logger"
)
var (
once sync.Once
localZKAlive int32
testClient *Client
)
func isLocalZKAlive(t *testing.T) bool {
once.Do(func() {
logger.SetLevel(logger.LevelDebug)
testClient = connectLocalZK(t)
if testClient == nil {
logger.Errorf("zk can't connect")
return
}
time.Sleep(time.Second)
if testClient.ConnAlive() {
atomic.StoreInt32(&localZKAlive, 1)
} else {
logger.Errorf("zk not alive")
testClient.Close()
}
})
alive := atomic.LoadInt32(&localZKAlive)
return alive == 1
}
func connectLocalZK(_ *testing.T) *Client {
c := NewClient([]string{"127.0.0.1:2181"})
if c.ConnAlive() {
logger.Errorf("zk can't connect")
return nil
}
return c
}
const (
watchWaitInterval = time.Second * 2
)
func waitEventWatch() {
time.Sleep(watchWaitInterval)
}