@@ -143,6 +143,42 @@ func TestGracefulShutdown(t *testing.T) {
143
143
testGracefulShutdown (t , conn , & inst )
144
144
}
145
145
146
+ func TestGracefulShutdownOnClose (t * testing.T ) {
147
+ test_helpers .SkipIfWatchersUnsupported (t )
148
+
149
+ var inst test_helpers.TarantoolInstance
150
+ var conn * Connection
151
+ var err error
152
+
153
+ inst , err = test_helpers .StartTarantool (shtdnSrvOpts )
154
+ require .Nil (t , err )
155
+ defer test_helpers .StopTarantoolWithCleanup (inst )
156
+
157
+ conn = test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
158
+ defer conn .Close ()
159
+
160
+ // Send request with sleep.
161
+ evalSleep := 3 // in seconds
162
+ require .Lessf (t ,
163
+ time .Duration (evalSleep )* time .Second ,
164
+ shtdnClntOpts .Timeout ,
165
+ "test request won't be failed by timeout" )
166
+
167
+ req := NewEvalRequest (evalBody ).Args ([]interface {}{evalSleep , evalMsg })
168
+ fut := conn .Do (req )
169
+
170
+ // Close the connection.
171
+ conn .Close ()
172
+
173
+ // Connection is closed.
174
+ require .Equal (t , true , conn .ClosedNow ())
175
+
176
+ // Check that request was successful.
177
+ resp , err := fut .Get ()
178
+ require .Nilf (t , err , "sleep request no error" )
179
+ require .NotNilf (t , resp , "sleep response exists" )
180
+ }
181
+
146
182
func TestGracefulShutdownWithReconnect (t * testing.T ) {
147
183
test_helpers .SkipIfWatchersUnsupported (t )
148
184
@@ -222,86 +258,6 @@ func TestNoGracefulShutdown(t *testing.T) {
222
258
"server went down without any additional waiting" )
223
259
}
224
260
225
- func TestGracefulShutdownRespectsClose (t * testing.T ) {
226
- test_helpers .SkipIfWatchersUnsupported (t )
227
-
228
- var inst test_helpers.TarantoolInstance
229
- var conn * Connection
230
- var err error
231
-
232
- inst , err = test_helpers .StartTarantool (shtdnSrvOpts )
233
- require .Nil (t , err )
234
- defer test_helpers .StopTarantoolWithCleanup (inst )
235
-
236
- conn = test_helpers .ConnectWithValidation (t , shtdnServer , shtdnClntOpts )
237
- defer conn .Close ()
238
-
239
- // Create a helper watcher to ensure that async
240
- // shutdown is set up.
241
- helperCh := make (chan WatchEvent , 10 )
242
- helperW , herr := conn .NewWatcher ("box.shutdown" , func (event WatchEvent ) {
243
- helperCh <- event
244
- })
245
- require .Nil (t , herr )
246
- defer helperW .Unregister ()
247
- <- helperCh
248
-
249
- // Set a big timeout so it would be easy to differ
250
- // if server went down on timeout or after all connections were terminated.
251
- serverShutdownTimeout := 60 // in seconds
252
- _ , err = conn .Call ("box.ctl.set_on_shutdown_timeout" , []interface {}{serverShutdownTimeout })
253
- require .Nil (t , err )
254
-
255
- // Send request with sleep.
256
- evalSleep := 10 // in seconds
257
- require .Lessf (t ,
258
- time .Duration (evalSleep )* time .Second ,
259
- shtdnClntOpts .Timeout ,
260
- "test request won't be failed by timeout" )
261
-
262
- req := NewEvalRequest (evalBody ).Args ([]interface {}{evalSleep , evalMsg })
263
-
264
- fut := conn .Do (req )
265
-
266
- // SIGTERM the server.
267
- shutdownStart := time .Now ()
268
- require .Nil (t , inst .Cmd .Process .Signal (syscall .SIGTERM ))
269
-
270
- // Close the connection.
271
- conn .Close ()
272
-
273
- // Connection is closed.
274
- require .Equal (t , true , conn .ClosedNow ())
275
-
276
- // Check that request was interrupted.
277
- _ , err = fut .Get ()
278
- require .NotNilf (t , err , "sleep request error" )
279
-
280
- // Wait until server go down.
281
- _ , err = inst .Cmd .Process .Wait ()
282
- require .Nil (t , err )
283
- shutdownFinish := time .Now ()
284
- shutdownTime := shutdownFinish .Sub (shutdownStart )
285
-
286
- // Help test helpers to properly clean up.
287
- inst .Cmd .Process = nil
288
-
289
- // Check that server finished without waiting for eval to finish.
290
- require .Lessf (t ,
291
- shutdownTime ,
292
- time .Duration (evalSleep / 2 )* time .Second ,
293
- "server went down without any additional waiting" )
294
-
295
- // Check that it wasn't a timeout.
296
- require .Lessf (t ,
297
- shutdownTime ,
298
- time .Duration (serverShutdownTimeout / 2 )* time .Second ,
299
- "server went down not by timeout" )
300
-
301
- // Connection is still closed.
302
- require .Equal (t , true , conn .ClosedNow ())
303
- }
304
-
305
261
func TestGracefulShutdownNotRacesWithRequestReconnect (t * testing.T ) {
306
262
test_helpers .SkipIfWatchersUnsupported (t )
307
263
0 commit comments