@@ -86,22 +86,6 @@ var defaultTimeoutRetry = 500 * time.Millisecond
86
86
87
87
var helpInstances []test_helpers.TarantoolInstance
88
88
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
-
105
89
func TestConnect_error_duplicate (t * testing.T ) {
106
90
ctx , cancel := test_helpers .GetPoolConnectContext ()
107
91
connPool , err := pool .Connect (ctx , makeInstances ([]string {"foo" , "foo" }, connOpts ))
@@ -145,6 +129,48 @@ func TestConnSuccessfully(t *testing.T) {
145
129
require .Nil (t , err )
146
130
}
147
131
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
+
148
174
func TestConnErrorAfterCtxCancel (t * testing.T ) {
149
175
var connLongReconnectOpts = tarantool.Opts {
150
176
Timeout : 5 * time .Second ,
@@ -410,16 +436,14 @@ func TestDisconnectAll(t *testing.T) {
410
436
func TestAdd (t * testing.T ) {
411
437
ctx , cancel := test_helpers .GetPoolConnectContext ()
412
438
defer cancel ()
413
- connPool , err := pool .Connect (ctx , makeInstances ( servers [: 1 ], connOpts ) )
439
+ connPool , err := pool .Connect (ctx , []pool. Instance {} )
414
440
require .Nilf (t , err , "failed to connect" )
415
441
require .NotNilf (t , connPool , "conn is nil after Connect" )
416
442
417
443
defer connPool .Close ()
418
444
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 ))
423
447
require .Nil (t , err )
424
448
}
425
449
@@ -452,9 +476,7 @@ func TestAdd_exist(t *testing.T) {
452
476
453
477
defer connPool .Close ()
454
478
455
- ctx , cancel = test_helpers .GetConnectContext ()
456
- err = connPool .Add (ctx , makeInstance (server , connOpts ))
457
- cancel ()
479
+ err = connPool .Add (makeInstance (server , connOpts ))
458
480
require .Equal (t , pool .ErrExists , err )
459
481
460
482
args := test_helpers.CheckStatusesArgs {
@@ -484,25 +506,23 @@ func TestAdd_unreachable(t *testing.T) {
484
506
defer connPool .Close ()
485
507
486
508
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 {
489
510
Name : unhealthyServ ,
490
511
Dialer : tarantool.NetDialer {
491
512
Address : unhealthyServ ,
492
513
},
493
514
Opts : connOpts ,
494
515
})
495
- cancel ()
496
- // The OS-dependent error so we just check for existence.
497
- require .NotNil (t , err )
516
+ require .NoError (t , err )
498
517
499
518
args := test_helpers.CheckStatusesArgs {
500
519
ConnPool : connPool ,
501
520
Mode : pool .ANY ,
502
521
Servers : servers ,
503
522
ExpectedPoolStatus : true ,
504
523
ExpectedStatuses : map [string ]bool {
505
- server : true ,
524
+ server : true ,
525
+ unhealthyServ : false ,
506
526
},
507
527
}
508
528
@@ -520,9 +540,7 @@ func TestAdd_afterClose(t *testing.T) {
520
540
require .NotNilf (t , connPool , "conn is nil after Connect" )
521
541
522
542
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 ))
526
544
assert .Equal (t , err , pool .ErrClosed )
527
545
}
528
546
@@ -541,9 +559,7 @@ func TestAdd_Close_concurrent(t *testing.T) {
541
559
go func () {
542
560
defer wg .Done ()
543
561
544
- ctx , cancel := test_helpers .GetConnectContext ()
545
- err = connPool .Add (ctx , makeInstance (serv1 , connOpts ))
546
- cancel ()
562
+ err = connPool .Add (makeInstance (serv1 , connOpts ))
547
563
if err != nil {
548
564
assert .Equal (t , pool .ErrClosed , err )
549
565
}
@@ -569,9 +585,7 @@ func TestAdd_CloseGraceful_concurrent(t *testing.T) {
569
585
go func () {
570
586
defer wg .Done ()
571
587
572
- ctx , cancel := test_helpers .GetConnectContext ()
573
- err = connPool .Add (ctx , makeInstance (serv1 , connOpts ))
574
- cancel ()
588
+ err = connPool .Add (makeInstance (serv1 , connOpts ))
575
589
if err != nil {
576
590
assert .Equal (t , pool .ErrClosed , err )
577
591
}
@@ -1028,7 +1042,12 @@ func TestConnectionHandlerOpenError(t *testing.T) {
1028
1042
if err == nil {
1029
1043
defer connPool .Close ()
1030
1044
}
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 ())
1032
1051
require .Equalf (t , 2 , h .discovered , "unexpected discovered count" )
1033
1052
require .Equalf (t , 0 , h .deactivated , "unexpected deactivated count" )
1034
1053
}
0 commit comments