Skip to content

Commit 7ab6953

Browse files
[Flaky Test] adjust timing of TestFilestreamTruncateBlockedOutput (#46576) (#46584)
(cherry picked from commit 5b5d933) Co-authored-by: Mauri de Souza Meneguzzo <[email protected]>
1 parent b3a5375 commit 7ab6953

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

filebeat/input/filestream/environment_test.go

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"testing"
3131
"time"
3232

33+
"github.com/stretchr/testify/assert"
3334
"github.com/stretchr/testify/require"
3435

3536
loginp "github.com/elastic/beats/v7/filebeat/input/filestream/internal/input-logfile"
@@ -229,33 +230,26 @@ func (e *inputTestingEnvironment) requireRegistryEntryCount(expectedCount int) {
229230
// requireOffsetInRegistry checks if the expected offset is set for a file.
230231
func (e *inputTestingEnvironment) requireOffsetInRegistry(filename, inputID string, expectedOffset int) {
231232
e.t.Helper()
232-
var offsetStr strings.Builder
233+
require.EventuallyWithT(e.t, func(ct *assert.CollectT) {
234+
var offsetStr strings.Builder
233235

234-
filepath := e.abspath(filename)
235-
fi, err := os.Stat(filepath)
236-
if err != nil {
237-
e.t.Fatalf("cannot stat file when cheking for offset: %+v", err)
238-
}
236+
filepath := e.abspath(filename)
237+
fi, err := os.Stat(filepath)
238+
assert.NoError(ct, err, "cannot stat file when checking for offset")
239239

240-
id := getIDFromPath(filepath, inputID, fi)
241-
var entry registryEntry
242-
require.Eventuallyf(e.t, func() bool {
240+
id := getIDFromPath(filepath, inputID, fi)
241+
var entry registryEntry
243242
offsetStr.Reset()
244243

245244
entry, err = e.getRegistryState(id)
246-
if err != nil {
247-
e.t.Fatalf("could not get state for '%s' from registry, err: %s", id, err)
248-
}
245+
assert.NoError(ct, err, "error getting state for ID '%s' from the registry", id)
249246

250247
fmt.Fprint(&offsetStr, entry.Cursor.Offset)
251-
252-
return expectedOffset == entry.Cursor.Offset
248+
assert.Equal(ct, expectedOffset, entry.Cursor.Offset, "expected offset does not match")
253249
},
254250
10*time.Second,
255251
100*time.Millisecond,
256-
"expected offset: '%d', cursor offset: '%s'",
257-
expectedOffset,
258-
&offsetStr)
252+
"failed to get expected registry offset")
259253
}
260254

261255
// requireMetaInRegistry checks if the expected metadata is saved to the registry.

0 commit comments

Comments
 (0)