@@ -86,22 +86,6 @@ var defaultTimeoutRetry = 500 * time.Millisecond
8686
8787var helpInstances []test_helpers.TarantoolInstance
8888
89- func TestConnect_error_empty_instances (t * testing.T ) {
90- ctx , cancel := test_helpers .GetPoolConnectContext ()
91- connPool , err := pool .Connect (ctx , []pool.Instance {})
92- cancel ()
93- require .Nilf (t , connPool , "conn is not nil with incorrect param" )
94- require .ErrorIs (t , err , pool .ErrEmptyInstances )
95- }
96-
97- func TestConnect_error_unavailable (t * testing.T ) {
98- ctx , cancel := test_helpers .GetPoolConnectContext ()
99- connPool , err := pool .Connect (ctx , makeInstances ([]string {"err1" , "err2" }, connOpts ))
100- cancel ()
101- require .Nilf (t , connPool , "conn is not nil with incorrect param" )
102- require .ErrorIs (t , err , pool .ErrNoConnection )
103- }
104-
10589func TestConnect_error_duplicate (t * testing.T ) {
10690 ctx , cancel := test_helpers .GetPoolConnectContext ()
10791 connPool , err := pool .Connect (ctx , makeInstances ([]string {"foo" , "foo" }, connOpts ))
@@ -145,6 +129,48 @@ func TestConnSuccessfully(t *testing.T) {
145129 require .Nil (t , err )
146130}
147131
132+ func TestConnect_empty (t * testing.T ) {
133+ cases := []struct {
134+ Name string
135+ Instances []pool.Instance
136+ }{
137+ {"nil" , nil },
138+ {"empty" , []pool.Instance {}},
139+ }
140+
141+ for _ , tc := range cases {
142+ t .Run (tc .Name , func (t * testing.T ) {
143+ ctx , cancel := test_helpers .GetPoolConnectContext ()
144+ defer cancel ()
145+ connPool , err := pool .Connect (ctx , tc .Instances )
146+ if connPool != nil {
147+ defer connPool .Close ()
148+ }
149+ require .NoError (t , err , "failed to create a pool" )
150+ require .NotNilf (t , connPool , "pool is nil after Connect" )
151+ require .Lenf (t , connPool .GetInfo (), 0 , "empty pool expected" )
152+ })
153+ }
154+ }
155+
156+ func TestConnect_unavailable (t * testing.T ) {
157+ servers := []string {"err1" , "err2" }
158+ ctx , cancel := test_helpers .GetPoolConnectContext ()
159+ connPool , err := pool .Connect (ctx , makeInstances ([]string {"err1" , "err2" }, connOpts ))
160+ cancel ()
161+
162+ if connPool != nil {
163+ defer connPool .Close ()
164+ }
165+
166+ require .NoError (t , err , "failed to create a pool" )
167+ require .NotNilf (t , connPool , "pool is nil after Connect" )
168+ require .Equal (t , map [string ]pool.ConnectionInfo {
169+ servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
170+ servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
171+ }, connPool .GetInfo ())
172+ }
173+
148174func TestConnErrorAfterCtxCancel (t * testing.T ) {
149175 var connLongReconnectOpts = tarantool.Opts {
150176 Timeout : 5 * time .Second ,
@@ -410,16 +436,14 @@ func TestDisconnectAll(t *testing.T) {
410436func TestAdd (t * testing.T ) {
411437 ctx , cancel := test_helpers .GetPoolConnectContext ()
412438 defer cancel ()
413- connPool , err := pool .Connect (ctx , makeInstances ( servers [: 1 ], connOpts ) )
439+ connPool , err := pool .Connect (ctx , []pool. Instance {} )
414440 require .Nilf (t , err , "failed to connect" )
415441 require .NotNilf (t , connPool , "conn is nil after Connect" )
416442
417443 defer connPool .Close ()
418444
419- for _ , server := range servers [1 :] {
420- ctx , cancel := test_helpers .GetConnectContext ()
421- err = connPool .Add (ctx , makeInstance (server , connOpts ))
422- cancel ()
445+ for _ , server := range servers {
446+ err = connPool .Add (makeInstance (server , connOpts ))
423447 require .Nil (t , err )
424448 }
425449
@@ -452,9 +476,7 @@ func TestAdd_exist(t *testing.T) {
452476
453477 defer connPool .Close ()
454478
455- ctx , cancel = test_helpers .GetConnectContext ()
456- err = connPool .Add (ctx , makeInstance (server , connOpts ))
457- cancel ()
479+ err = connPool .Add (makeInstance (server , connOpts ))
458480 require .Equal (t , pool .ErrExists , err )
459481
460482 args := test_helpers.CheckStatusesArgs {
@@ -484,25 +506,23 @@ func TestAdd_unreachable(t *testing.T) {
484506 defer connPool .Close ()
485507
486508 unhealthyServ := "127.0.0.2:6667"
487- ctx , cancel = test_helpers .GetConnectContext ()
488- err = connPool .Add (ctx , pool.Instance {
509+ err = connPool .Add (pool.Instance {
489510 Name : unhealthyServ ,
490511 Dialer : tarantool.NetDialer {
491512 Address : unhealthyServ ,
492513 },
493514 Opts : connOpts ,
494515 })
495- cancel ()
496- // The OS-dependent error so we just check for existence.
497- require .NotNil (t , err )
516+ require .NoError (t , err )
498517
499518 args := test_helpers.CheckStatusesArgs {
500519 ConnPool : connPool ,
501520 Mode : pool .ANY ,
502521 Servers : servers ,
503522 ExpectedPoolStatus : true ,
504523 ExpectedStatuses : map [string ]bool {
505- server : true ,
524+ server : true ,
525+ unhealthyServ : false ,
506526 },
507527 }
508528
@@ -520,9 +540,7 @@ func TestAdd_afterClose(t *testing.T) {
520540 require .NotNilf (t , connPool , "conn is nil after Connect" )
521541
522542 connPool .Close ()
523- ctx , cancel = test_helpers .GetConnectContext ()
524- err = connPool .Add (ctx , makeInstance (server , connOpts ))
525- cancel ()
543+ err = connPool .Add (makeInstance (server , connOpts ))
526544 assert .Equal (t , err , pool .ErrClosed )
527545}
528546
@@ -541,9 +559,7 @@ func TestAdd_Close_concurrent(t *testing.T) {
541559 go func () {
542560 defer wg .Done ()
543561
544- ctx , cancel := test_helpers .GetConnectContext ()
545- err = connPool .Add (ctx , makeInstance (serv1 , connOpts ))
546- cancel ()
562+ err = connPool .Add (makeInstance (serv1 , connOpts ))
547563 if err != nil {
548564 assert .Equal (t , pool .ErrClosed , err )
549565 }
@@ -569,9 +585,7 @@ func TestAdd_CloseGraceful_concurrent(t *testing.T) {
569585 go func () {
570586 defer wg .Done ()
571587
572- ctx , cancel := test_helpers .GetConnectContext ()
573- err = connPool .Add (ctx , makeInstance (serv1 , connOpts ))
574- cancel ()
588+ err = connPool .Add (makeInstance (serv1 , connOpts ))
575589 if err != nil {
576590 assert .Equal (t , pool .ErrClosed , err )
577591 }
@@ -1028,7 +1042,12 @@ func TestConnectionHandlerOpenError(t *testing.T) {
10281042 if err == nil {
10291043 defer connPool .Close ()
10301044 }
1031- require .NotNilf (t , err , "success to connect" )
1045+ require .NoError (t , err , "failed to connect" )
1046+ require .NotNil (t , connPool , "pool expected" )
1047+ require .Equal (t , map [string ]pool.ConnectionInfo {
1048+ servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
1049+ servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
1050+ }, connPool .GetInfo ())
10321051 require .Equalf (t , 2 , h .discovered , "unexpected discovered count" )
10331052 require .Equalf (t , 0 , h .deactivated , "unexpected deactivated count" )
10341053}
0 commit comments