Skip to content

Commit 7295758

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

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"
@@ -241,33 +242,26 @@ func (e *inputTestingEnvironment) requireRegistryEntryCount(expectedCount int) {
241242
// requireOffsetInRegistry checks if the expected offset is set for a file.
242243
func (e *inputTestingEnvironment) requireOffsetInRegistry(filename, inputID string, expectedOffset int) {
243244
e.t.Helper()
244-
var offsetStr strings.Builder
245+
require.EventuallyWithT(e.t, func(ct *assert.CollectT) {
246+
var offsetStr strings.Builder
245247

246-
filepath := e.abspath(filename)
247-
fi, err := os.Stat(filepath)
248-
if err != nil {
249-
e.t.Fatalf("cannot stat file when cheking for offset: %+v", err)
250-
}
248+
filepath := e.abspath(filename)
249+
fi, err := os.Stat(filepath)
250+
assert.NoError(ct, err, "cannot stat file when checking for offset")
251251

252-
id := getIDFromPath(filepath, inputID, fi)
253-
var entry registryEntry
254-
require.Eventuallyf(e.t, func() bool {
252+
id := getIDFromPath(filepath, inputID, fi)
253+
var entry registryEntry
255254
offsetStr.Reset()
256255

257256
entry, err = e.getRegistryState(id)
258-
if err != nil {
259-
e.t.Fatalf("could not get state for '%s' from registry, err: %s", id, err)
260-
}
257+
assert.NoError(ct, err, "error getting state for ID '%s' from the registry", id)
261258

262259
fmt.Fprint(&offsetStr, entry.Cursor.Offset)
263-
264-
return expectedOffset == entry.Cursor.Offset
260+
assert.Equal(ct, expectedOffset, entry.Cursor.Offset, "expected offset does not match")
265261
},
266262
10*time.Second,
267263
100*time.Millisecond,
268-
"expected offset: '%d', cursor offset: '%s'",
269-
expectedOffset,
270-
&offsetStr)
264+
"failed to get expected registry offset")
271265
}
272266

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

0 commit comments

Comments
 (0)