@@ -31,6 +31,8 @@ var connOptsMulti = OptsMulti{
31
31
ClusterDiscoveryTime : 3 * time .Second ,
32
32
}
33
33
34
+ var instances []test_helpers.TarantoolInstance
35
+
34
36
func TestConnError_IncorrectParams (t * testing.T ) {
35
37
multiConn , err := Connect ([]string {}, tarantool.Opts {})
36
38
if err == nil {
@@ -118,36 +120,41 @@ func TestReconnect(t *testing.T) {
118
120
}
119
121
120
122
func TestDisconnectAll (t * testing.T ) {
121
- multiConn , _ := Connect ([]string {server1 , server2 }, connOpts )
123
+ sleep := 100 * time .Millisecond
124
+ sleepCnt := int ((time .Second / sleep ) * 2 ) // Checkout time * 2.
125
+
126
+ servers := []string {server1 , server2 }
127
+ multiConn , _ := Connect (servers , connOpts )
122
128
if multiConn == nil {
123
129
t .Errorf ("conn is nil after Connect" )
124
130
return
125
131
}
126
- timer := time .NewTimer (300 * time .Millisecond )
127
- <- timer .C
128
- defer multiConn .Close ()
129
132
130
- conn , _ := multiConn .getConnectionFromPool (server1 )
131
- conn .Close ()
132
- conn , _ = multiConn .getConnectionFromPool (server2 )
133
- conn .Close ()
133
+ for _ , inst := range instances {
134
+ test_helpers .StopTarantoolWithCleanup (inst )
135
+ }
136
+
137
+ for i := 0 ; i < sleepCnt && multiConn .ConnectedNow (); i ++ {
138
+ time .Sleep (sleep )
139
+ }
134
140
135
141
if multiConn .ConnectedNow () {
136
142
t .Errorf ("incorrect status after desconnect all" )
137
143
}
138
144
139
- timer = time .NewTimer (100 * time .Millisecond )
140
- <- timer .C
141
- if ! multiConn .ConnectedNow () {
142
- t .Errorf ("incorrect multiConn status after reconnecting" )
145
+ for _ , inst := range instances {
146
+ err := test_helpers .RestartTarantool (& inst )
147
+ if err != nil {
148
+ t .Fatalf ("failed to restart Tarantool: %s" , err )
149
+ }
143
150
}
144
- conn , _ = multiConn . getConnectionFromPool ( server1 )
145
- if ! conn .ConnectedNow () {
146
- t . Errorf ( "incorrect server1 conn status after reconnecting" )
151
+
152
+ for i := 0 ; i < sleepCnt && ! multiConn .ConnectedNow (); i ++ {
153
+ time . Sleep ( sleep )
147
154
}
148
- conn , _ = multiConn . getConnectionFromPool ( server2 )
149
- if ! conn .ConnectedNow () {
150
- t .Errorf ("incorrect server2 conn status after reconnecting" )
155
+
156
+ if ! multiConn .ConnectedNow () {
157
+ t .Errorf ("incorrect multiConn status after reconnecting" )
151
158
}
152
159
}
153
160
@@ -589,36 +596,23 @@ func runTestMain(m *testing.M) int {
589
596
log .Fatalf ("Could not check the Tarantool version" )
590
597
}
591
598
592
- inst1 , err := test_helpers .StartTarantool (test_helpers.StartOpts {
599
+ servers := []string {server1 , server2 }
600
+ instances , err = test_helpers .StartTarantoolInstances (servers , nil , test_helpers.StartOpts {
593
601
InitScript : initScript ,
594
- Listen : server1 ,
595
602
User : connOpts .User ,
596
603
Pass : connOpts .Pass ,
597
604
WaitStart : waitStart ,
598
605
ConnectRetry : connectRetry ,
599
606
RetryTimeout : retryTimeout ,
600
607
MemtxUseMvccEngine : ! isStreamUnsupported ,
601
608
})
602
- defer test_helpers .StopTarantoolWithCleanup (inst1 )
603
609
604
610
if err != nil {
605
611
log .Fatalf ("Failed to prepare test tarantool: %s" , err )
612
+ return - 1
606
613
}
607
614
608
- inst2 , err := test_helpers .StartTarantool (test_helpers.StartOpts {
609
- InitScript : initScript ,
610
- Listen : server2 ,
611
- User : connOpts .User ,
612
- Pass : connOpts .Pass ,
613
- WaitStart : waitStart ,
614
- ConnectRetry : connectRetry ,
615
- RetryTimeout : retryTimeout ,
616
- })
617
- defer test_helpers .StopTarantoolWithCleanup (inst2 )
618
-
619
- if err != nil {
620
- log .Fatalf ("Failed to prepare test tarantool: %s" , err )
621
- }
615
+ defer test_helpers .StopTarantoolInstances (instances )
622
616
623
617
return m .Run ()
624
618
}
0 commit comments