Skip to content

Commit

Permalink
increase timeout for fbreceiver test, and make sure logs are current
Browse files Browse the repository at this point in the history
  • Loading branch information
leehinman committed Sep 25, 2024
1 parent f9749b0 commit 66d5c70
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion x-pack/filebeat/fbreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestNewReceiver(t *testing.T) {
"path.home": t.TempDir(),
},
}

var zapLogs bytes.Buffer
core := zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
Expand All @@ -61,8 +62,27 @@ func TestNewReceiver(t *testing.T) {
err = r.Start(context.Background(), nil)
assert.NoError(t, err, "Error starting filebeatreceiver")

assert.Eventuallyf(t, func() bool { return countLogs > 0 }, 60*time.Second, 1*time.Second, "consumed logs didn't increase\nCount: %d\nLogs: %s\n", countLogs, zapLogs.String())
ch := make(chan bool, 1)
timer := time.NewTimer(120 * time.Second)
defer timer.Stop()
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()

for tick := ticker.C; ; {
select {
case <-timer.C:
t.Fatalf("consumed logs didn't increase\nCount: %d\nLogs: %s\n", countLogs, zapLogs.String())
case <-tick:
tick = nil
go func() { ch <- countLogs > 0 }()
case v := <-ch:
if v {
goto found
}
tick = ticker.C
}
}
found:
err = r.Shutdown(context.Background())
assert.NoError(t, err, "Error shutting down filebeatreceiver")
}

0 comments on commit 66d5c70

Please sign in to comment.