@@ -242,7 +242,9 @@ func TestConnect_empty(t *testing.T) {
242242func TestConnect_unavailable (t * testing.T ) {
243243 servers := []string {"err1" , "err2" }
244244 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 )
246248 cancel ()
247249
248250 if connPool != nil {
@@ -252,8 +254,8 @@ func TestConnect_unavailable(t *testing.T) {
252254 require .NoError (t , err , "failed to create a pool" )
253255 require .NotNilf (t , connPool , "pool is nil after Connect" )
254256 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 ] },
257259 }, connPool .GetInfo ())
258260}
259261
@@ -1156,15 +1158,17 @@ func TestConnectionHandlerOpenError(t *testing.T) {
11561158 }
11571159 ctx , cancel := test_helpers .GetPoolConnectContext ()
11581160 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 )
11601164 if err == nil {
11611165 defer connPool .Close ()
11621166 }
11631167 require .NoError (t , err , "failed to connect" )
11641168 require .NotNil (t , connPool , "pool expected" )
11651169 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 ] },
11681172 }, connPool .GetInfo ())
11691173 connPool .Close ()
11701174
@@ -3495,6 +3499,39 @@ func runTestMain(m *testing.M) int {
34953499 return m .Run ()
34963500}
34973501
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+
34983535func TestMain (m * testing.M ) {
34993536 code := runTestMain (m )
35003537 os .Exit (code )
0 commit comments