Skip to content

Commit

Permalink
testing: set env in docker entrypoint for logstash (#3994)
Browse files Browse the repository at this point in the history
Also make the test that revealed the failure a bit more strict
  • Loading branch information
7AC authored and tsg committed Apr 12, 2017
1 parent 6c49522 commit 63bd071
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
26 changes: 19 additions & 7 deletions libbeat/outputs/logstash/logstash_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,18 @@ func (es *esConnection) Count() (int, error) {
return resp.Count, nil
}

func waitUntilTrue(duration time.Duration, fn func() bool) bool {
func waitUntilTrue(duration time.Duration, fn func() bool) (bool, time.Duration) {
end := time.Now().Add(duration)
var timeSlept time.Duration
sleepTime := 100 * time.Millisecond
for time.Now().Before(end) {
if fn() {
return true
return true, timeSlept
}
time.Sleep(100 * time.Millisecond)
time.Sleep(sleepTime)
timeSlept += sleepTime
}
return false
return false, timeSlept
}

func checkIndex(reader esCountReader, minValues int) func() bool {
Expand Down Expand Up @@ -269,10 +272,18 @@ func testSendMessageViaLogstash(t *testing.T, name string, tls bool) {
"type": "log",
"message": "hello world",
}}
ls.PublishEvent(nil, testOptions, event)
err := ls.PublishEvent(nil, testOptions, event)
if err != nil {
t.Fatalf("failed to publish to Logstash: %s", err)
}

// wait for logstash event flush + elasticsearch
waitUntilTrue(5*time.Second, checkIndex(ls, 1))
timeout := 5 * time.Second
if ok, waited := waitUntilTrue(timeout, checkIndex(ls, 1)); !ok {
t.Fatalf("Logstash event flush timed out after %s", timeout)
} else {
t.Logf("Logstash event flushed after %s", waited)
}

// search value in logstash elasticsearch index
resp, err := ls.Read()
Expand Down Expand Up @@ -377,8 +388,9 @@ func testSendMultipleBatchesViaLogstash(
}

// wait for logstash event flush + elasticsearch
ok := waitUntilTrue(5*time.Second, checkIndex(ls, numBatches*batchSize))
ok, waited := waitUntilTrue(5*time.Second, checkIndex(ls, numBatches*batchSize))
assert.True(t, ok) // check number of events matches total number of events
t.Logf("Logstash event flushed after %s", waited)

// search value in logstash elasticsearch index
resp, err := ls.Read()
Expand Down
1 change: 1 addition & 0 deletions testing/environments/docker/logstash/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ updateConfigFile() {

# Main

readParams
updateConfigFile
waitForElasticsearch
exec "$@"

0 comments on commit 63bd071

Please sign in to comment.