Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky test - increase file lifespan in rotation tests #1384

Merged
merged 8 commits into from
Oct 29, 2020
1 change: 0 additions & 1 deletion receiver/stanzareceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ It can also be easily configured to tail and parse any structured or unstructure
- [timestamp](https://github.com/observIQ/stanza/blob/master/docs/types/timestamp.md) parsing is available as a block within all parser operators, and also as a standalone operator. Many common timestamp layouts are supported.
- [severity](https://github.com/observIQ/stanza/blob/master/docs/types/severity.md) parsing is available as a block within all parser operators, and also as a standalone operator. Stanza uses a flexible severity representation which is automatically interpreted by the stanza receiver.


## Example - Tailing a simple json file

Receiver Configuration
Expand Down
19 changes: 12 additions & 7 deletions receiver/stanzareceiver/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"log"
"os"
"path/filepath"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -109,10 +108,6 @@ func TestReadStaticFile(t *testing.T) {
}

func TestReadRotatingFiles(t *testing.T) {
// https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/1382
if runtime.GOOS == "windows" {
t.Skip()
}

tests := []rotationTest{
{
Expand Down Expand Up @@ -196,10 +191,20 @@ func (rt *rotationTest) Run(t *testing.T) {

for _, line := range lines {
logger.Print(line)
time.Sleep(time.Millisecond)
// At a high enough rate of file rotation, it is possible for a file to be deleted
// before all lines can be read from it. In production settings, this is far less
// likely because log files will exists for much longer durations, except in the
// most extreme scenarios. This test attempts to establish a stable scenario that
// does not consume much time by balancing the max lines per file with a duration
// of existence that is low enough to be practical in a unit test. The following
// sleep provides a level of consistency to file lifespan.
time.Sleep(2 * time.Millisecond)
}

require.Eventually(t, expectNLogs(sink, numLogs), 2*time.Second, time.Millisecond)
missingMsg := func(exp, act int) string { return fmt.Sprintf("%d out of expected %d received", act, exp) }

waitFor, tick := 2*time.Second, time.Millisecond
require.Eventually(t, expectNLogs(sink, numLogs), waitFor, tick, missingMsg(numLogs, sink.LogRecordsCount()))
require.ElementsMatch(t, expectedLogs, sink.AllLogs())
require.NoError(t, rcvr.Shutdown(context.Background()))
}
Expand Down