@@ -57,14 +57,15 @@ func TestGossip(t *testing.T) {
57
57
sort .Ints (tcpPorts )
58
58
59
59
// wait for convergence
60
- converge (5 * time .Second , nsqds , convergenceTester .c , func () bool {
60
+ converged := converge (5 * time .Second , nsqds , convergenceTester .c , func () bool {
61
61
for _ , nsqd := range nsqds {
62
62
if len (nsqd .rdb .FindProducers ("client" , "" , "" )) != num {
63
63
return false
64
64
}
65
65
}
66
66
return true
67
67
})
68
+ equal (t , converged , true )
68
69
69
70
// all nodes in the cluster should have registrations
70
71
for _ , nsqd := range nsqds {
@@ -85,7 +86,7 @@ func TestGossip(t *testing.T) {
85
86
topic .GetChannel ("ch" )
86
87
firstPort := nsqds [0 ].tcpListener .Addr ().(* net.TCPAddr ).Port
87
88
88
- converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
89
+ converged = converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
89
90
for _ , nsqd := range nsqds {
90
91
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
91
92
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -94,6 +95,7 @@ func TestGossip(t *testing.T) {
94
95
}
95
96
return true
96
97
})
98
+ equal (t , converged , true )
97
99
98
100
for _ , nsqd := range nsqds {
99
101
producers := nsqd .rdb .FindProducers ("topic" , topicName , "" )
@@ -127,6 +129,10 @@ func TestGossipResync(t *testing.T) {
127
129
opts .Logger = newTestLogger (t )
128
130
opts .GossipAddress = addr .String ()
129
131
opts .BroadcastAddress = "127.0.0.1"
132
+ opts .GossipReapInterval = 200 * time .Millisecond
133
+ opts .GossipReconnectTimeout = 100 * time .Millisecond
134
+ opts .GossipSuspicionMult = 1
135
+ opts .GossipProbeInterval = 100 * time .Millisecond
130
136
opts .gossipDelegate = convergenceTester
131
137
if seedNode != nil {
132
138
opts .GossipSeedAddresses = []string {seedNode .getOpts ().GossipAddress }
@@ -150,7 +156,7 @@ func TestGossipResync(t *testing.T) {
150
156
topic .GetChannel ("ch" )
151
157
firstPort := nsqds [0 ].tcpListener .Addr ().(* net.TCPAddr ).Port
152
158
153
- converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
159
+ converged := converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
154
160
for _ , nsqd := range nsqds {
155
161
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
156
162
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -159,6 +165,7 @@ func TestGossipResync(t *testing.T) {
159
165
}
160
166
return true
161
167
})
168
+ equal (t , converged , true )
162
169
163
170
for _ , nsqd := range nsqds {
164
171
producers := nsqd .rdb .FindProducers ("topic" , topicName , "" )
@@ -175,32 +182,34 @@ func TestGossipResync(t *testing.T) {
175
182
stillAlive := nsqds [:num - 1 ]
176
183
177
184
// check that other nodes see it as closed
178
- converge (10 * time .Second , stillAlive , convergenceTester .c , func () bool {
185
+ converged = converge (10 * time .Second , stillAlive , convergenceTester .c , func () bool {
179
186
for _ , nsqd := range stillAlive {
180
187
if len (nsqd .serf .Members ()) != len (stillAlive ) {
181
188
return false
182
189
}
183
190
}
184
191
return true
185
192
})
193
+ equal (t , converged , true )
186
194
187
195
// restart stopped node
188
196
_ , _ , nsqd := mustStartNSQD (nsqds [num - 1 ].getOpts ())
189
197
defer nsqd .Exit ()
190
198
nsqds [num - 1 ] = nsqd
191
199
192
200
// check that other nodes see it as back open
193
- converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
201
+ converged = converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
194
202
for _ , nsqd := range nsqds {
195
203
if len (nsqd .serf .Members ()) != len (nsqds ) {
196
204
return false
197
205
}
198
206
}
199
207
return true
200
208
})
209
+ equal (t , converged , true )
201
210
202
211
// check that all nodes see the restarted first node
203
- converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
212
+ converged = converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
204
213
for _ , nsqd := range nsqds {
205
214
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
206
215
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -209,6 +218,7 @@ func TestGossipResync(t *testing.T) {
209
218
}
210
219
return true
211
220
})
221
+ equal (t , converged , true )
212
222
213
223
// we should have producers for the topic/channel back now
214
224
for _ , nsqd := range nsqds {
@@ -266,7 +276,7 @@ func TestRegossip(t *testing.T) {
266
276
topic .GetChannel ("ch" )
267
277
firstPort := nsqds [0 ].tcpListener .Addr ().(* net.TCPAddr ).Port
268
278
269
- converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
279
+ converged := converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
270
280
for _ , nsqd := range nsqds {
271
281
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
272
282
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -275,6 +285,7 @@ func TestRegossip(t *testing.T) {
275
285
}
276
286
return true
277
287
})
288
+ equal (t , converged , true )
278
289
279
290
for _ , nsqd := range nsqds {
280
291
producers := nsqd .rdb .FindProducers ("topic" , topicName , "" )
@@ -294,7 +305,7 @@ func TestRegossip(t *testing.T) {
294
305
}
295
306
296
307
// wait for regossip
297
- converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
308
+ converged = converge (10 * time .Second , nsqds , convergenceTester .c , func () bool {
298
309
for _ , nsqd := range nsqds {
299
310
if len (nsqd .rdb .FindProducers ("topic" , topicName , "" )) != 1 ||
300
311
len (nsqd .rdb .FindProducers ("channel" , topicName , "ch" )) != 1 {
@@ -303,6 +314,7 @@ func TestRegossip(t *testing.T) {
303
314
}
304
315
return true
305
316
})
317
+ equal (t , converged , true )
306
318
307
319
// we should have producers for the topic/channel back now on all nodes
308
320
for _ , nsqd := range nsqds {
@@ -316,16 +328,17 @@ func TestRegossip(t *testing.T) {
316
328
}
317
329
}
318
330
319
- func converge (timeout time.Duration , nsqds []* NSQD , notifyChan chan struct {}, isConverged func () bool ) {
320
- // wait for convergence
321
- converged := false
322
- t := time .NewTimer (timeout )
323
- for ! converged {
331
+ func converge (timeout time.Duration , nsqds []* NSQD , notifyChan chan struct {}, isConverged func () bool ) bool {
332
+ for {
324
333
select {
325
- case <- t . C :
326
- converged = true
334
+ case <- time . After ( timeout ) :
335
+ return false
327
336
case <- notifyChan :
328
- converged = isConverged ()
337
+ if isConverged () {
338
+ goto exit
339
+ }
329
340
}
330
341
}
342
+ exit:
343
+ return true
331
344
}
0 commit comments