@@ -127,9 +127,15 @@ func TestGracefulShutdown(t *testing.T) {
127
127
require .Nil (t , err )
128
128
defer test_helpers .StopTarantoolWithCleanup (inst )
129
129
130
+ shtdnNotify := make (chan WatchEvent , 10 )
131
+ shtdnClntOpts .ShutdownNotify = shtdnNotify
132
+
130
133
conn = test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
131
134
defer conn .Close ()
132
135
136
+ // Wait till Tarantool register out watcher.
137
+ <- shtdnNotify
138
+
133
139
testGracefulShutdown (t , conn , & inst )
134
140
}
135
141
@@ -143,17 +149,29 @@ func TestGracefulShutdownWithReconnect(t *testing.T) {
143
149
require .Nil (t , err )
144
150
defer test_helpers .StopTarantoolWithCleanup (inst )
145
151
152
+ shtdnNotify := make (chan WatchEvent , 10 )
153
+ shtdnClntOpts .ShutdownNotify = shtdnNotify
154
+
146
155
conn := test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
147
156
defer conn .Close ()
148
157
158
+ // Wait till Tarantool register out watcher.
159
+ <- shtdnNotify
160
+
149
161
testGracefulShutdown (t , conn , & inst )
150
162
163
+ // Skip shutdown event.
164
+ <- shtdnNotify
165
+
151
166
err = test_helpers .RestartTarantool (& inst )
152
167
require .Nilf (t , err , "Failed to restart tarantool" )
153
168
154
169
connected := test_helpers .WaitUntilReconnected (conn , shtdnClntOpts .MaxReconnects , shtdnClntOpts .Reconnect )
155
170
require .Truef (t , connected , "Reconnect success" )
156
171
172
+ // Wait till Tarantool register out watcher.
173
+ <- shtdnNotify
174
+
157
175
testGracefulShutdown (t , conn , & inst )
158
176
}
159
177
@@ -241,9 +259,15 @@ func TestGracefulShutdownRespectsClose(t *testing.T) {
241
259
require .Nil (t , err )
242
260
defer test_helpers .StopTarantoolWithCleanup (inst )
243
261
262
+ shtdnNotify := make (chan WatchEvent , 10 )
263
+ shtdnClntOpts .ShutdownNotify = shtdnNotify
264
+
244
265
conn = test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
245
266
defer conn .Close ()
246
267
268
+ // Wait till Tarantool register out watcher.
269
+ <- shtdnNotify
270
+
247
271
// Set a big timeout so it would be easy to differ
248
272
// if server went down on timeout or after all connections were terminated.
249
273
serverShutdownTimeout := 60 // in seconds
@@ -311,9 +335,15 @@ func TestGracefulShutdownNotRacesWithRequestReconnect(t *testing.T) {
311
335
require .Nil (t , err )
312
336
defer test_helpers .StopTarantoolWithCleanup (inst )
313
337
338
+ shtdnNotify := make (chan WatchEvent , 10 )
339
+ shtdnClntOpts .ShutdownNotify = shtdnNotify
340
+
314
341
conn = test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
315
342
defer conn .Close ()
316
343
344
+ // Wait till Tarantool register out watcher.
345
+ <- shtdnNotify
346
+
317
347
// Set a small timeout so server will shutdown before requesst finishes.
318
348
serverShutdownTimeout := 1 // in seconds
319
349
_ , err = conn .Call ("box.ctl.set_on_shutdown_timeout" , []interface {}{serverShutdownTimeout })
@@ -394,6 +424,9 @@ func TestGracefulShutdownCloseConcurrent(t *testing.T) {
394
424
go func (i int ) {
395
425
defer caseWg .Done ()
396
426
427
+ // Do not wait till Tarantool register out watcher,
428
+ // test everything is ok even on async.
429
+
397
430
conn := test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
398
431
defer conn .Close ()
399
432
@@ -463,12 +496,18 @@ func TestGracefulShutdownConcurrent(t *testing.T) {
463
496
// Create many connections.
464
497
var ret error
465
498
for i := 0 ; i < testConcurrency ; i ++ {
466
- go func (i int ) {
499
+ go func (i int , opts Opts ) {
467
500
defer caseWg .Done ()
468
501
469
- conn := test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
502
+ shtdnNotify := make (chan WatchEvent , 10 )
503
+ opts .ShutdownNotify = shtdnNotify
504
+
505
+ conn := test_helpers .ConnectWithValidation (t , shtdnServer , opts )
470
506
defer conn .Close ()
471
507
508
+ // Wait till Tarantool register out watcher.
509
+ <- shtdnNotify
510
+
472
511
evalSleep := 1 // in seconds
473
512
req := NewEvalRequest (evalBody ).Args ([]interface {}{evalSleep , evalMsg })
474
513
fut := conn .Do (req )
@@ -482,6 +521,7 @@ func TestGracefulShutdownConcurrent(t *testing.T) {
482
521
ret = gerr
483
522
}
484
523
}(i )
524
+ }(i , shtdnClntOpts )
485
525
}
486
526
487
527
var sret error
0 commit comments