@@ -75,32 +75,23 @@ func TestDeadTimeout(t *testing.T) {
75
75
}
76
76
77
77
var pool ConnectionPool
78
-
79
78
urls := []string {"localhost:9200" , "localhost:9201" }
80
-
81
79
err := pool .SetConnections (urls , "test" , "secret" )
82
80
if err != nil {
83
81
t .Errorf ("Fail to set the connections: %s" , err )
84
82
}
85
- pool .SetDeadTimeout (10 )
83
+ // Set dead timeout to zero so that dead connections are immediately
84
+ // returned to the pool.
85
+ pool .SetDeadTimeout (0 )
86
86
87
87
conn := pool .GetConnection ()
88
+ assertExpectedConnectionURL (t , conn .URL , urls [0 ])
88
89
89
- if conn .URL != "localhost:9200" {
90
- t .Errorf ("Wrong connection returned: %s" , conn .URL )
91
- }
92
90
pool .MarkDead (conn )
93
- time .Sleep (10 * time .Second )
94
-
95
- conn = pool .GetConnection ()
96
- if conn .URL != "localhost:9201" {
97
- t .Errorf ("Wrong connection returned: %s" , conn .URL )
98
- }
91
+ time .Sleep (1 * time .Millisecond )
99
92
100
- conn = pool .GetConnection ()
101
- if conn .URL != "localhost:9200" {
102
- t .Errorf ("Wrong connection returned: %s" , conn .URL )
103
- }
93
+ assertExpectedConnectionURL (t , pool .GetConnection ().URL , urls [1 ])
94
+ assertExpectedConnectionURL (t , pool .GetConnection ().URL , urls [0 ])
104
95
}
105
96
106
97
func TestMarkLive (t * testing.T ) {
@@ -130,5 +121,10 @@ func TestMarkLive(t *testing.T) {
130
121
if conn .URL != "localhost:9200" {
131
122
t .Errorf ("Wrong connection returned: %s" , conn .URL )
132
123
}
124
+ }
133
125
126
+ func assertExpectedConnectionURL (t testing.TB , returned , expected string ) {
127
+ if returned != expected {
128
+ t .Errorf ("Wrong connection returned: %s, expecting: %s" , returned , expected )
129
+ }
134
130
}
0 commit comments