@@ -3550,6 +3550,72 @@ func TestConnection_NewWatcher(t *testing.T) {
3550
3550
}
3551
3551
}
3552
3552
3553
+ func TestNewWatcherDuringReconnectOrAfterClose (t * testing.T ) {
3554
+ test_helpers .SkipIfWatchersUnsupported (t )
3555
+
3556
+ prepareTestConnection := func () (* Connection , context.CancelFunc ) {
3557
+ t .Helper ()
3558
+
3559
+ const server = "127.0.0.1:3015"
3560
+ testDialer := dialer
3561
+ testDialer .Address = server
3562
+
3563
+ inst , err := test_helpers .StartTarantool (test_helpers.StartOpts {
3564
+ Dialer : testDialer ,
3565
+ InitScript : "config.lua" ,
3566
+ Listen : server ,
3567
+ WaitStart : 100 * time .Millisecond ,
3568
+ ConnectRetry : 10 ,
3569
+ RetryTimeout : 500 * time .Millisecond ,
3570
+ })
3571
+ t .Cleanup (func () { test_helpers .StopTarantoolWithCleanup (inst ) })
3572
+ if err != nil {
3573
+ t .Fatalf ("Unable to start Tarantool: %s" , err )
3574
+ }
3575
+
3576
+ ctx , cancel := test_helpers .GetConnectContext ()
3577
+
3578
+ reconnectOpts := opts
3579
+ reconnectOpts .Reconnect = 100 * time .Millisecond
3580
+ reconnectOpts .MaxReconnects = 0
3581
+ reconnectOpts .Notify = make (chan ConnEvent )
3582
+ conn , err := Connect (ctx , testDialer , reconnectOpts )
3583
+ if err != nil {
3584
+ t .Fatalf ("Connection was not established: %v" , err )
3585
+ }
3586
+
3587
+ test_helpers .StopTarantool (inst )
3588
+
3589
+ // wait for reconnection process to be started
3590
+ for conn .ConnectedNow () {
3591
+ time .Sleep (100 * time .Millisecond )
3592
+ }
3593
+
3594
+ return conn , cancel
3595
+ }
3596
+
3597
+ t .Run ("during reconnect" , func (t * testing.T ) {
3598
+ conn , cancel := prepareTestConnection ()
3599
+ defer conn .Close ()
3600
+ defer cancel ()
3601
+
3602
+ _ , err := conn .NewWatcher ("one" , func (event WatchEvent ) {})
3603
+ assert .NotNil (t , err )
3604
+ assert .ErrorContains (t , err , "client connection is not ready" )
3605
+ })
3606
+
3607
+ t .Run ("after close" , func (t * testing.T ) {
3608
+ conn , cancel := prepareTestConnection ()
3609
+ defer cancel ()
3610
+
3611
+ _ = conn .Close ()
3612
+
3613
+ _ , err := conn .NewWatcher ("one" , func (event WatchEvent ) {})
3614
+ assert .NotNil (t , err )
3615
+ assert .ErrorContains (t , err , "using closed connection" )
3616
+ })
3617
+ }
3618
+
3553
3619
func TestConnection_NewWatcher_noWatchersFeature (t * testing.T ) {
3554
3620
test_helpers .SkipIfWatchersSupported (t )
3555
3621
@@ -4149,13 +4215,13 @@ func runTestMain(m *testing.M) int {
4149
4215
startOpts .MemtxUseMvccEngine = ! isStreamUnsupported
4150
4216
4151
4217
inst , err := test_helpers .StartTarantool (startOpts )
4152
- defer test_helpers .StopTarantoolWithCleanup (inst )
4153
-
4154
4218
if err != nil {
4155
4219
log .Printf ("Failed to prepare test tarantool: %s" , err )
4156
4220
return 1
4157
4221
}
4158
4222
4223
+ defer test_helpers .StopTarantoolWithCleanup (inst )
4224
+
4159
4225
return m .Run ()
4160
4226
}
4161
4227
0 commit comments