MCPcopy Create free account
hub / github.com/apache/kvrocks-controller / TestElect

Function TestElect

store/engine/postgresql/postgresql_test.go:76–124  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestElect(t *testing.T) {
77 endpoints := []string{addr}
78
79 testElectPath := util.RandString(32)
80 id0 := util.RandString(40)
81 node0, err := New(id0, &Config{
82 Username: username,
83 Password: password,
84 DBName: dbName,
85 NotifyChannel: notifyChannel,
86 ElectPath: testElectPath,
87 Addrs: endpoints,
88 })
89 require.NoError(t, err)
90 require.Eventuallyf(t, func() bool {
91 return node0.Leader() == node0.myID
92 }, 10*time.Second, 100*time.Millisecond, "node0 should be the leader")
93
94 id1 := util.RandString(40)
95 node1, err := New(id1, &Config{
96 Username: username,
97 Password: password,
98 DBName: dbName,
99 NotifyChannel: notifyChannel,
100 ElectPath: testElectPath,
101 Addrs: endpoints,
102 })
103 require.NoError(t, err)
104 require.Eventuallyf(t, func() bool {
105 return node1.Leader() == node0.myID
106 }, 10*time.Second, 100*time.Millisecond, "node1's leader should be the node0")
107
108 go func() {
109 for {
110 select {
111 case <-node0.LeaderChange():
112 // do nothing
113 case <-node1.LeaderChange():
114 // do nothing
115 }
116 }
117 }()
118
119 require.NoError(t, node0.Close())
120
121 require.Eventuallyf(t, func() bool {
122 return node1.Leader() == node1.myID
123 }, 15*time.Second, 100*time.Millisecond, "node1 should be the leader")
124}

Callers

nothing calls this directly

Calls 5

RandStringFunction · 0.92
NewFunction · 0.70
LeaderMethod · 0.65
LeaderChangeMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected