@@ -92,30 +92,49 @@ func TestConnSuccessfully(t *testing.T) {
92
92
}
93
93
94
94
func TestReconnect (t * testing.T ) {
95
- multiConn , _ := Connect ([]string {server1 , server2 }, connOpts )
95
+ sleep := 100 * time .Millisecond
96
+ sleepCnt := 50
97
+ servers := []string {server1 , server2 }
98
+ multiConn , _ := Connect (servers , connOpts )
96
99
if multiConn == nil {
97
100
t .Errorf ("conn is nil after Connect" )
98
101
return
99
102
}
100
- timer := time .NewTimer (300 * time .Millisecond )
101
- <- timer .C
102
- defer multiConn .Close ()
103
+ test_helpers .StopTarantoolWithCleanup (instances [0 ])
103
104
104
- conn , _ := multiConn .getConnectionFromPool (server1 )
105
- conn .Close ()
105
+ for i := 0 ; i < sleepCnt ; i ++ {
106
+ _ , ok := multiConn .getConnectionFromPool (servers [0 ])
107
+ if ! ok {
108
+ break
109
+ }
110
+ time .Sleep (sleep )
111
+ }
112
+
113
+ _ , ok := multiConn .getConnectionFromPool (servers [0 ])
114
+ if ok {
115
+ t .Fatalf ("failed to close conn" )
116
+ }
106
117
107
- if multiConn .getCurrentConnection ().Addr () == server1 {
118
+ if multiConn .getCurrentConnection ().Addr () == servers [ 0 ] {
108
119
t .Errorf ("conn has incorrect addr: %s after disconnect server1" , multiConn .getCurrentConnection ().Addr ())
109
120
}
110
- if ! multiConn .ConnectedNow () {
111
- t .Errorf ("incorrect multiConn status after reconnecting" )
121
+
122
+ err := test_helpers .RestartTarantool (& instances [0 ])
123
+ if err != nil {
124
+ t .Fatalf ("failed to restart Tarantool: %s" , err )
112
125
}
113
126
114
- timer = time .NewTimer (100 * time .Millisecond )
115
- <- timer .C
116
- conn , _ = multiConn .getConnectionFromPool (server1 )
117
- if ! conn .ConnectedNow () {
118
- t .Errorf ("incorrect conn status after reconnecting" )
127
+ for i := 0 ; i < sleepCnt ; i ++ {
128
+ _ , ok := multiConn .getConnectionFromPool (servers [0 ])
129
+ if ok {
130
+ break
131
+ }
132
+ time .Sleep (sleep )
133
+ }
134
+
135
+ _ , ok = multiConn .getConnectionFromPool (servers [0 ])
136
+ if ! ok {
137
+ t .Fatalf ("incorrect conn status after reconnecting" )
119
138
}
120
139
}
121
140
0 commit comments