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

Cherry-pick #21625 to 7.x: Fix flaky FSWatch/FSScanner tests #21676

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 7 additions & 25 deletions filebeat/input/filestream/fswatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ var (
)

func TestFileScanner(t *testing.T) {
t.Skip("Flaky test: https://github.com/elastic/beats/issues/21489")

testCases := map[string]struct {
paths []string
excludedFiles []match.Matcher
Expand Down Expand Up @@ -89,7 +87,7 @@ func TestFileScanner(t *testing.T) {
for p, _ := range files {
paths = append(paths, p)
}
assert.True(t, checkIfSameContents(test.expectedFiles, paths))
assert.ElementsMatch(t, paths, test.expectedFiles)
})
}
}
Expand All @@ -116,26 +114,7 @@ func removeFilesOfScannerTest(t *testing.T) {
}
}

// only handles sets
func checkIfSameContents(one, other []string) bool {
if len(one) != len(other) {
return false
}

mustFind := len(one)
for _, oneElem := range one {
for _, otherElem := range other {
if oneElem == otherElem {
mustFind--
}
}
}
return mustFind == 0
}

func TestFileWatchNewDeleteModified(t *testing.T) {
t.Skip("Flaky test: https://github.com/elastic/beats/issues/21489")

oldTs := time.Now()
newTs := oldTs.Add(5 * time.Second)
testCases := map[string]struct {
Expand Down Expand Up @@ -226,10 +205,13 @@ func TestFileWatchNewDeleteModified(t *testing.T) {

go w.watch(context.Background())

for _, expectedEvent := range test.expectedEvents {
evt := w.Event()
assert.Equal(t, expectedEvent, evt)
count := len(test.expectedEvents)
actual := make([]loginp.FSEvent, count)
for i := 0; i < count; i++ {
actual[i] = w.Event()
}

assert.ElementsMatch(t, actual, test.expectedEvents)
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion filebeat/input/filestream/fswatch_test_non_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestFileScannerSymlinks(t *testing.T) {
for p, _ := range files {
paths = append(paths, p)
}
assert.Equal(t, test.expectedFiles, paths)
assert.ElementsMatch(t, test.expectedFiles, paths)
})
}
}
Expand Down