diff --git a/filebeat/input/filestream/fswatch_test.go b/filebeat/input/filestream/fswatch_test.go index d6286a273eb..2435fad1500 100644 --- a/filebeat/input/filestream/fswatch_test.go +++ b/filebeat/input/filestream/fswatch_test.go @@ -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 @@ -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) }) } } @@ -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 { @@ -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) }) } } diff --git a/filebeat/input/filestream/fswatch_test_non_windows.go b/filebeat/input/filestream/fswatch_test_non_windows.go index eecfeddf930..3c316efdfc9 100644 --- a/filebeat/input/filestream/fswatch_test_non_windows.go +++ b/filebeat/input/filestream/fswatch_test_non_windows.go @@ -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) }) } }