@@ -242,7 +242,9 @@ func TestConnect_empty(t *testing.T) {
242
242
func TestConnect_unavailable (t * testing.T ) {
243
243
servers := []string {"err1" , "err2" }
244
244
ctx , cancel := test_helpers .GetPoolConnectContext ()
245
- connPool , err := pool .Connect (ctx , makeInstances ([]string {"err1" , "err2" }, connOpts ))
245
+ insts := makeInstances ([]string {"err1" , "err2" }, connOpts )
246
+
247
+ connPool , err := pool .Connect (ctx , insts )
246
248
cancel ()
247
249
248
250
if connPool != nil {
@@ -252,8 +254,8 @@ func TestConnect_unavailable(t *testing.T) {
252
254
require .NoError (t , err , "failed to create a pool" )
253
255
require .NotNilf (t , connPool , "pool is nil after Connect" )
254
256
require .Equal (t , map [string ]pool.ConnectionInfo {
255
- servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
256
- servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
257
+ servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [ 0 ] },
258
+ servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [ 1 ] },
257
259
}, connPool .GetInfo ())
258
260
}
259
261
@@ -1156,15 +1158,17 @@ func TestConnectionHandlerOpenError(t *testing.T) {
1156
1158
}
1157
1159
ctx , cancel := test_helpers .GetPoolConnectContext ()
1158
1160
defer cancel ()
1159
- connPool , err := pool .ConnectWithOpts (ctx , makeInstances (poolServers , connOpts ), poolOpts )
1161
+
1162
+ insts := makeInstances (poolServers , connOpts )
1163
+ connPool , err := pool .ConnectWithOpts (ctx , insts , poolOpts )
1160
1164
if err == nil {
1161
1165
defer connPool .Close ()
1162
1166
}
1163
1167
require .NoError (t , err , "failed to connect" )
1164
1168
require .NotNil (t , connPool , "pool expected" )
1165
1169
require .Equal (t , map [string ]pool.ConnectionInfo {
1166
- servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
1167
- servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
1170
+ servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [ 0 ] },
1171
+ servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [ 1 ] },
1168
1172
}, connPool .GetInfo ())
1169
1173
connPool .Close ()
1170
1174
@@ -3495,6 +3499,39 @@ func runTestMain(m *testing.M) int {
3495
3499
return m .Run ()
3496
3500
}
3497
3501
3502
+ func TestConnectionPool_GetInfo (t * testing.T ) {
3503
+ t .Run ("equal instance info" , func (t * testing.T ) {
3504
+ var tCases [][]pool.Instance
3505
+
3506
+ tCases = append (tCases , makeInstances ([]string {servers [0 ], servers [1 ]}, connOpts ))
3507
+ tCases = append (tCases , makeInstances ([]string {
3508
+ servers [0 ],
3509
+ servers [1 ],
3510
+ servers [3 ]},
3511
+ connOpts ))
3512
+ tCases = append (tCases , makeInstances ([]string {servers [0 ]}, connOpts ))
3513
+
3514
+ for _ , tc := range tCases {
3515
+ ctx , cancel := test_helpers .GetPoolConnectContext ()
3516
+ connPool , err := pool .Connect (ctx , tc )
3517
+ cancel ()
3518
+ require .Nilf (t , err , "failed to connect" )
3519
+ require .NotNilf (t , connPool , "conn is nil after Connect" )
3520
+
3521
+ info := connPool .GetInfo ()
3522
+
3523
+ var infoInstances []pool.Instance
3524
+
3525
+ for _ , infoInst := range info {
3526
+ infoInstances = append (infoInstances , infoInst .Instance )
3527
+ }
3528
+
3529
+ require .ElementsMatch (t , tc , infoInstances )
3530
+ connPool .Close ()
3531
+ }
3532
+ })
3533
+ }
3534
+
3498
3535
func TestMain (m * testing.M ) {
3499
3536
code := runTestMain (m )
3500
3537
os .Exit (code )
0 commit comments