@@ -7,25 +7,11 @@ import (
7
7
"time"
8
8
)
9
9
10
- type gossipTester struct {
11
- c chan struct {}
12
- }
13
-
14
- func (g gossipTester ) notify () {
15
- g .c <- struct {}{}
16
- select {
17
- case g .c <- struct {}{}:
18
- default :
19
- }
20
- }
21
-
22
10
func TestGossip (t * testing.T ) {
23
11
var nsqds []* NSQD
24
12
var seedNode * NSQD
25
13
var tcpPorts []int
26
14
27
- convergenceTester := gossipTester {make (chan struct {}, 20 )}
28
-
29
15
num := 3
30
16
for i := 0 ; i < num ; i ++ {
31
17
// find an open port
@@ -39,7 +25,6 @@ func TestGossip(t *testing.T) {
39
25
opts .Logger = newTestLogger (t )
40
26
opts .GossipAddress = addr .String ()
41
27
opts .BroadcastAddress = "127.0.0.1"
42
- opts .gossipDelegate = convergenceTester
43
28
if seedNode != nil {
44
29
opts .GossipSeedAddresses = []string {seedNode .getOpts ().GossipAddress }
45
30
}
@@ -57,7 +42,7 @@ func TestGossip(t *testing.T) {
57
42
sort .Ints (tcpPorts )
58
43
59
44
// wait for convergence
60
- converged := converge (5 * time .Second , nsqds , convergenceTester . c , func () bool {
45
+ converged := converge (5 * time .Second , nsqds , func () bool {
61
46
for _ , nsqd := range nsqds {
62
47
if len (nsqd .rdb .FindProducers ("client" , "" , "" )) != num {
63
48
return false
@@ -86,7 +71,7 @@ func TestGossip(t *testing.T) {
86
71
topic .GetChannel ("ch" )
87
72
firstPort := nsqds [0 ].tcpListener .Addr ().(* net.TCPAddr ).Port
88
73
89
- converged = converge (10 * time .Second , nsqds , convergenceTester . c , func () bool {
74
+ converged = converge (10 * time .Second , nsqds , func () bool {
90
75
for _ , nsqd := range nsqds {
91
76
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
92
77
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -114,8 +99,6 @@ func TestGossipResync(t *testing.T) {
114
99
var seedNode * NSQD
115
100
var tcpPorts []int
116
101
117
- convergenceTester := gossipTester {make (chan struct {}, 20 )}
118
-
119
102
num := 3
120
103
for i := 0 ; i < num ; i ++ {
121
104
// find an open port
@@ -133,7 +116,6 @@ func TestGossipResync(t *testing.T) {
133
116
opts .GossipReconnectTimeout = 100 * time .Millisecond
134
117
opts .GossipSuspicionMult = 1
135
118
opts .GossipProbeInterval = 100 * time .Millisecond
136
- opts .gossipDelegate = convergenceTester
137
119
if seedNode != nil {
138
120
opts .GossipSeedAddresses = []string {seedNode .getOpts ().GossipAddress }
139
121
}
@@ -156,7 +138,7 @@ func TestGossipResync(t *testing.T) {
156
138
topic .GetChannel ("ch" )
157
139
firstPort := nsqds [0 ].tcpListener .Addr ().(* net.TCPAddr ).Port
158
140
159
- converged := converge (10 * time .Second , nsqds , convergenceTester . c , func () bool {
141
+ converged := converge (10 * time .Second , nsqds , func () bool {
160
142
for _ , nsqd := range nsqds {
161
143
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
162
144
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -182,7 +164,7 @@ func TestGossipResync(t *testing.T) {
182
164
stillAlive := nsqds [:num - 1 ]
183
165
184
166
// check that other nodes see it as closed
185
- converged = converge (10 * time .Second , stillAlive , convergenceTester . c , func () bool {
167
+ converged = converge (10 * time .Second , stillAlive , func () bool {
186
168
for _ , nsqd := range stillAlive {
187
169
if len (nsqd .serf .Members ()) != len (stillAlive ) {
188
170
return false
@@ -198,7 +180,7 @@ func TestGossipResync(t *testing.T) {
198
180
nsqds [num - 1 ] = nsqd
199
181
200
182
// check that other nodes see it as back open
201
- converged = converge (10 * time .Second , nsqds , convergenceTester . c , func () bool {
183
+ converged = converge (10 * time .Second , nsqds , func () bool {
202
184
for _ , nsqd := range nsqds {
203
185
if len (nsqd .serf .Members ()) != len (nsqds ) {
204
186
return false
@@ -209,7 +191,7 @@ func TestGossipResync(t *testing.T) {
209
191
equal (t , converged , true )
210
192
211
193
// check that all nodes see the restarted first node
212
- converged = converge (10 * time .Second , nsqds , convergenceTester . c , func () bool {
194
+ converged = converge (10 * time .Second , nsqds , func () bool {
213
195
for _ , nsqd := range nsqds {
214
196
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
215
197
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -237,8 +219,6 @@ func TestRegossip(t *testing.T) {
237
219
var seedNode * NSQD
238
220
var tcpPorts []int
239
221
240
- convergenceTester := gossipTester {make (chan struct {}, 20 )}
241
-
242
222
num := 3
243
223
for i := 0 ; i < num ; i ++ {
244
224
// find an open port
@@ -253,7 +233,6 @@ func TestRegossip(t *testing.T) {
253
233
opts .GossipAddress = addr .String ()
254
234
opts .BroadcastAddress = "127.0.0.1"
255
235
opts .GossipRegossipInterval = 1 * time .Second
256
- opts .gossipDelegate = convergenceTester
257
236
if seedNode != nil {
258
237
opts .GossipSeedAddresses = []string {seedNode .getOpts ().GossipAddress }
259
238
}
@@ -276,7 +255,7 @@ func TestRegossip(t *testing.T) {
276
255
topic .GetChannel ("ch" )
277
256
firstPort := nsqds [0 ].tcpListener .Addr ().(* net.TCPAddr ).Port
278
257
279
- converged := converge (10 * time .Second , nsqds , convergenceTester . c , func () bool {
258
+ converged := converge (10 * time .Second , nsqds , func () bool {
280
259
for _ , nsqd := range nsqds {
281
260
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
282
261
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -305,7 +284,7 @@ func TestRegossip(t *testing.T) {
305
284
}
306
285
307
286
// wait for regossip
308
- converged = converge (10 * time .Second , nsqds , convergenceTester . c , func () bool {
287
+ converged = converge (10 * time .Second , nsqds , func () bool {
309
288
for _ , nsqd := range nsqds {
310
289
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
311
290
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -328,12 +307,12 @@ func TestRegossip(t *testing.T) {
328
307
}
329
308
}
330
309
331
- func converge (timeout time.Duration , nsqds []* NSQD , notifyChan chan struct {}, isConverged func () bool ) bool {
310
+ func converge (timeout time.Duration , nsqds []* NSQD , isConverged func () bool ) bool {
332
311
for {
333
312
select {
334
313
case <- time .After (timeout ):
335
314
return false
336
- case <- notifyChan :
315
+ case <- time . After ( 10 * time . Millisecond ) :
337
316
if isConverged () {
338
317
goto exit
339
318
}
0 commit comments