Skip to content

Commit

Permalink
filebeat: Fix flaky test case on macOS (#39860) (#39897)
Browse files Browse the repository at this point in the history
* fix: fix a flaky test on macos

* fix: fix more such test cases

* fix: only update ignore_older

* fix: also fix flaky test_restart_state

* fix: fix CI

(cherry picked from commit f9fec1e)

Co-authored-by: VihasMakwana <[email protected]>
  • Loading branch information
mergify[bot] and VihasMakwana authored Jun 14, 2024
1 parent 522cf44 commit 6c3500f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions filebeat/tests/system/test_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def test_tail_files(self):
self.wait_until(
lambda: self.log_contains(
"Start next scan"),
max_timeout=5)
max_timeout=10)

with open(testfile, 'a') as f:
# write additional lines
Expand Down Expand Up @@ -596,7 +596,7 @@ def test_encodings(self):
# run filebeat
filebeat = self.start_beat()
self.wait_until(lambda: self.output_has(lines=len(encodings)),
max_timeout=15)
max_timeout=25)

# write another line in all files
for _, enc_py, text in encodings:
Expand Down
2 changes: 1 addition & 1 deletion filebeat/tests/system/test_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,6 @@ def test_debug_reader(self):

# 13 on unix, 14 on windows.
self.wait_until(lambda: self.log_contains(re.compile(
'Matching null byte found at offset (13|14)')), max_timeout=5)
'Matching null byte found at offset (13|14)')), max_timeout=10)

filebeat.check_kill_and_wait()
14 changes: 8 additions & 6 deletions filebeat/tests/system/test_registrar.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,11 @@ def test_registry_file_update_permissions(self):

self.assertEqual(self.file_permissions(os.path.join(registry_path, "log.json")), "0o600")

registry_home = "a/b/c/d/registry_x"
registry_path = os.path.join(registry_home, "filebeat")
self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
registry_home="a/b/c/registry_x",
registry_home=registry_home,
registry_file_permissions=0o640
)

Expand All @@ -266,7 +268,7 @@ def test_registry_file_update_permissions(self):
# the logging and actual writing the file. Seems to happen on Windows.
self.wait_until(
lambda: self.has_registry(registry_path),
max_timeout=1)
max_timeout=10)

# Wait a moment to make sure registry is completely written
time.sleep(1)
Expand Down Expand Up @@ -950,7 +952,7 @@ def test_restart_state(self):
path=os.path.abspath(self.working_dir) + "/log/*",
close_inactive="200ms",
ignore_older="2000ms",
clean_inactive="3s",
clean_inactive="10s",
)

filebeat = self.start_beat()
Expand All @@ -976,7 +978,7 @@ def test_restart_state_reset(self):
self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/*",
clean_inactive="10s",
ignore_older="5s"
ignore_older="9s"
)
os.mkdir(self.working_dir + "/log/")

Expand All @@ -1003,7 +1005,7 @@ def test_restart_state_reset(self):
self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/test2.log",
clean_inactive="10s",
ignore_older="5s",
ignore_older="9s",
)

filebeat = self.start_beat(output="filebeat2.log")
Expand Down Expand Up @@ -1137,7 +1139,7 @@ def test_restart_state_reset_ttl_no_clean_inactive(self):
self.render_config_template(
path=os.path.abspath(self.working_dir) + "/log/test.log",
clean_inactive="10s",
ignore_older="5s"
ignore_older="9s"
)
os.mkdir(self.working_dir + "/log/")

Expand Down
8 changes: 7 additions & 1 deletion filebeat/tests/system/test_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ def test_shutdown(self):
)
for i in range(1, 5):
proc = self.start_beat(logging_args=["-e", "-v"])
time.sleep(.5)

# Flaky on MacOS, see https://github.com/elastic/beats/issues/39613#issuecomment-2158812325
# we need to wait a bit longer for filebeat to start
if platform.system() == "Darwin":
time.sleep(10)
else:
time.sleep(.5)
proc.check_kill_and_wait()

@unittest.skip("Skipped as flaky: https://github.com/elastic/beats/issues/14647")
Expand Down

0 comments on commit 6c3500f

Please sign in to comment.