8000 Merge pull request #102 from andrewkroh/agonzalezro-dead_timeout-test · packplusplus/libbeat@dd2535e · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit dd2535e

Browse files
committed
Merge pull request #102 from andrewkroh/agonzalezro-dead_timeout-test
Agonzalezro dead timeout test
2 parents 79fdab2 + 4fd752f commit dd2535e

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

outputs/elasticsearch/connection_pool_test.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,23 @@ func TestDeadTimeout(t *testing.T) {
7575
}
7676

7777
var pool ConnectionPool
78-
7978
urls := []string{"localhost:9200", "localhost:9201"}
80-
8179
err := pool.SetConnections(urls, "test", "secret")
8280
if err != nil {
8381
t.Errorf("Fail to set the connections: %s", err)
8482
}
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)
8686

8787
conn := pool.GetConnection()
88+
assertExpectedConnectionURL(t, conn.URL, urls[0])
8889

89-
if conn.URL != "localhost:9200" {
90-
t.Errorf("Wrong connection returned: %s", conn.URL)
91-
}
9290
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)
9992

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])
10495
}
10596

10697
func TestMarkLive(t *testing.T) {
@@ -130,5 +121,10 @@ func TestMarkLive(t *testing.T) {
130121
if conn.URL != "localhost:9200" {
131122
t.Errorf("Wrong connection returned: %s", conn.URL)
132123
}
124+
}
133125

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+
}
134130
}

0 commit comments

Comments
 (0)
0