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