@@ -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,10 @@ 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 {
258+ ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [0 ]},
259+ servers [1 ]: pool.ConnectionInfo {
260+ ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [1 ]},
257261 }, connPool .GetInfo ())
258262}
259263
@@ -1156,15 +1160,19 @@ func TestConnectionHandlerOpenError(t *testing.T) {
11561160 }
11571161 ctx , cancel := test_helpers .GetPoolConnectContext ()
11581162 defer cancel ()
1159- connPool , err := pool .ConnectWithOpts (ctx , makeInstances (poolServers , connOpts ), poolOpts )
1163+
1164+ insts := makeInstances (poolServers , connOpts )
1165+ connPool , err := pool .ConnectWithOpts (ctx , insts , poolOpts )
11601166 if err == nil {
11611167 defer connPool .Close ()
11621168 }
11631169 require .NoError (t , err , "failed to connect" )
11641170 require .NotNil (t , connPool , "pool expected" )
11651171 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 },
1172+ servers [0 ]: pool.ConnectionInfo {
1173+ ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [0 ]},
1174+ servers [1 ]: pool.ConnectionInfo {
1175+ ConnectedNow : false , ConnRole : pool .UnknownRole , Instance : insts [1 ]},
11681176 }, connPool .GetInfo ())
11691177 connPool .Close ()
11701178
@@ -3495,6 +3503,37 @@ func runTestMain(m *testing.M) int {
34953503 return m .Run ()
34963504}
34973505
3506+ func TestConnectionPool_GetInfo_equal_instance_info (t * testing.T ) {
3507+ var tCases [][]pool.Instance
3508+
3509+ tCases = append (tCases , makeInstances ([]string {servers [0 ], servers [1 ]}, connOpts ))
3510+ tCases = append (tCases , makeInstances ([]string {
3511+ servers [0 ],
3512+ servers [1 ],
3513+ servers [3 ]},
3514+ connOpts ))
3515+ tCases = append (tCases , makeInstances ([]string {servers [0 ]}, connOpts ))
3516+
3517+ for _ , tc := range tCases {
3518+ ctx , cancel := test_helpers .GetPoolConnectContext ()
3519+ connPool , err := pool .Connect (ctx , tc )
3520+ cancel ()
3521+ require .Nilf (t , err , "failed to connect" )
3522+ require .NotNilf (t , connPool , "conn is nil after Connect" )
3523+
3524+ info := connPool .GetInfo ()
3525+
3526+ var infoInstances []pool.Instance
3527+
3528+ for _ , infoInst := range info {
3529+ infoInstances = append (infoInstances , infoInst .Instance )
3530+ }
3531+
3532+ require .ElementsMatch (t , tc , infoInstances )
3533+ connPool .Close ()
3534+ }
3535+ }
3536+
34983537func TestMain (m * testing.M ) {
34993538 code := runTestMain (m )
35003539 os .Exit (code )
0 commit comments