@@ -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 ))
@@ -138,13 +122,56 @@ func TestConnSuccessfully(t *testing.T) {
138
122
ExpectedPoolStatus : true ,
139
123
ExpectedStatuses : map [string ]bool {
140
124
healthyServ : true ,
125
+ "err" : false ,
141
126
},
142
127
}
143
128
144
129
err = test_helpers .CheckPoolStatuses (args )
145
130
require .Nil (t , err )
146
131
}
147
132
133
+ func TestConnect_empty (t * testing.T ) {
134
+ cases := []struct {
135
+ Name string
136
+ Instances []pool.Instance
137
+ }{
138
+ {"nil" , nil },
139
+ {"empty" , []pool.Instance {}},
140
+ }
141
+
142
+ for _ , tc := range cases {
143
+ t .Run (tc .Name , func (t * testing.T ) {
144
+ ctx , cancel := test_helpers .GetPoolConnectContext ()
145
+ defer cancel ()
146
+ connPool , err := pool .Connect (ctx , tc .Instances )
147
+ if connPool != nil {
148
+ defer connPool .Close ()
149
+ }
150
+ require .NoError (t , err , "failed to create a pool" )
151
+ require .NotNilf (t , connPool , "pool is nil after Connect" )
152
+ require .Lenf (t , connPool .GetInfo (), 0 , "empty pool expected" )
153
+ })
154
+ }
155
+ }
156
+
157
+ func TestConnect_unavailable (t * testing.T ) {
158
+ servers := []string {"err1" , "err2" }
159
+ ctx , cancel := test_helpers .GetPoolConnectContext ()
160
+ connPool , err := pool .Connect (ctx , makeInstances ([]string {"err1" , "err2" }, connOpts ))
161
+ cancel ()
162
+
163
+ if connPool != nil {
164
+ defer connPool .Close ()
165
+ }
166
+
167
+ require .NoError (t , err , "failed to create a pool" )
168
+ require .NotNilf (t , connPool , "pool is nil after Connect" )
169
+ require .Equal (t , map [string ]pool.ConnectionInfo {
170
+ servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
171
+ servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
172
+ }, connPool .GetInfo ())
173
+ }
174
+
148
175
func TestConnErrorAfterCtxCancel (t * testing.T ) {
149
176
var connLongReconnectOpts = tarantool.Opts {
150
177
Timeout : 5 * time .Second ,
@@ -410,16 +437,14 @@ func TestDisconnectAll(t *testing.T) {
410
437
func TestAdd (t * testing.T ) {
411
438
ctx , cancel := test_helpers .GetPoolConnectContext ()
412
439
defer cancel ()
413
- connPool , err := pool .Connect (ctx , makeInstances ( servers [: 1 ], connOpts ) )
440
+ connPool , err := pool .Connect (ctx , []pool. Instance {} )
414
441
require .Nilf (t , err , "failed to connect" )
415
442
require .NotNilf (t , connPool , "conn is nil after Connect" )
416
443
417
444
defer connPool .Close ()
418
445
419
- for _ , server := range servers [1 :] {
420
- ctx , cancel := test_helpers .GetConnectContext ()
421
- err = connPool .Add (ctx , makeInstance (server , connOpts ))
422
- cancel ()
446
+ for _ , server := range servers {
447
+ err = connPool .Add (makeInstance (server , connOpts ))
423
448
require .Nil (t , err )
424
449
}
425
450
@@ -452,9 +477,7 @@ func TestAdd_exist(t *testing.T) {
452
477
453
478
defer connPool .Close ()
454
479
455
- ctx , cancel = test_helpers .GetConnectContext ()
456
- err = connPool .Add (ctx , makeInstance (server , connOpts ))
457
- cancel ()
480
+ err = connPool .Add (makeInstance (server , connOpts ))
458
481
require .Equal (t , pool .ErrExists , err )
459
482
460
483
args := test_helpers.CheckStatusesArgs {
@@ -484,25 +507,23 @@ func TestAdd_unreachable(t *testing.T) {
484
507
defer connPool .Close ()
485
508
486
509
unhealthyServ := "127.0.0.2:6667"
487
- ctx , cancel = test_helpers .GetConnectContext ()
488
- err = connPool .Add (ctx , pool.Instance {
510
+ err = connPool .Add (pool.Instance {
489
511
Name : unhealthyServ ,
490
512
Dialer : tarantool.NetDialer {
491
513
Address : unhealthyServ ,
492
514
},
493
515
Opts : connOpts ,
494
516
})
495
- cancel ()
496
- // The OS-dependent error so we just check for existence.
497
- require .NotNil (t , err )
517
+ require .NoError (t , err )
498
518
499
519
args := test_helpers.CheckStatusesArgs {
500
520
ConnPool : connPool ,
501
521
Mode : pool .ANY ,
502
522
Servers : servers ,
503
523
ExpectedPoolStatus : true ,
504
524
ExpectedStatuses : map [string ]bool {
505
- server : true ,
525
+ server : true ,
526
+ unhealthyServ : false ,
506
527
},
507
528
}
508
529
@@ -520,9 +541,7 @@ func TestAdd_afterClose(t *testing.T) {
520
541
require .NotNilf (t , connPool , "conn is nil after Connect" )
521
542
522
543
connPool .Close ()
523
- ctx , cancel = test_helpers .GetConnectContext ()
524
- err = connPool .Add (ctx , makeInstance (server , connOpts ))
525
- cancel ()
544
+ err = connPool .Add (makeInstance (server , connOpts ))
526
545
assert .Equal (t , err , pool .ErrClosed )
527
546
}
528
547
@@ -541,9 +560,7 @@ func TestAdd_Close_concurrent(t *testing.T) {
541
560
go func () {
542
561
defer wg .Done ()
543
562
544
- ctx , cancel := test_helpers .GetConnectContext ()
545
- err = connPool .Add (ctx , makeInstance (serv1 , connOpts ))
546
- cancel ()
563
+ err = connPool .Add (makeInstance (serv1 , connOpts ))
547
564
if err != nil {
548
565
assert .Equal (t , pool .ErrClosed , err )
549
566
}
@@ -569,9 +586,7 @@ func TestAdd_CloseGraceful_concurrent(t *testing.T) {
569
586
go func () {
570
587
defer wg .Done ()
571
588
572
- ctx , cancel := test_helpers .GetConnectContext ()
573
- err = connPool .Add (ctx , makeInstance (serv1 , connOpts ))
574
- cancel ()
589
+ err = connPool .Add (makeInstance (serv1 , connOpts ))
575
590
if err != nil {
576
591
assert .Equal (t , pool .ErrClosed , err )
577
592
}
@@ -1028,8 +1043,17 @@ func TestConnectionHandlerOpenError(t *testing.T) {
1028
1043
if err == nil {
1029
1044
defer connPool .Close ()
1030
1045
}
1031
- require .NotNilf (t , err , "success to connect" )
1032
- require .Equalf (t , 2 , h .discovered , "unexpected discovered count" )
1046
+ require .NoError (t , err , "failed to connect" )
1047
+ require .NotNil (t , connPool , "pool expected" )
1048
+ require .Equal (t , map [string ]pool.ConnectionInfo {
1049
+ servers [0 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
1050
+ servers [1 ]: pool.ConnectionInfo {ConnectedNow : false , ConnRole : pool .UnknownRole },
1051
+ }, connPool .GetInfo ())
1052
+ connPool .Close ()
1053
+
1054
+ // It could happen additional reconnect attempts in the background, but
1055
+ // at least 2 connects on start.
1056
+ require .GreaterOrEqualf (t , h .discovered , 2 , "unexpected discovered count" )
1033
1057
require .Equalf (t , 0 , h .deactivated , "unexpected deactivated count" )
1034
1058
}
1035
1059
0 commit comments