Skip to content

Commit

Permalink
[tests][filebeat] fix flaky unit test cases (#40389) (#40401)
Browse files Browse the repository at this point in the history
* fix: fix flaky unit test cases

* fix: fix test_reload_same_config

(cherry picked from commit 4fbf1b1)

Co-authored-by: VihasMakwana <[email protected]>
  • Loading branch information
mergify[bot] and VihasMakwana authored Aug 1, 2024
1 parent 5374c6e commit 5bdb7eb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
14 changes: 6 additions & 8 deletions filebeat/tests/system/test_reload_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_reload(self):
os.mkdir(self.working_dir + "/configs/")

with open(self.working_dir + "/configs/input.yml", 'w') as f:
f.write(inputConfigTemplate.format(self.working_dir + "/logs/*"))
f.write(inputConfigTemplate.format(self.working_dir + "/logs/*.log"))

with open(logfile, 'w') as f:
f.write("Hello world\n")
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_start_stop(self):
os.mkdir(self.working_dir + "/configs/")

with open(self.working_dir + "/configs/input.yml", 'w') as f:
f.write(inputConfigTemplate.format(self.working_dir + "/logs/*"))
f.write(inputConfigTemplate.format(self.working_dir + "/logs/*.log"))

with open(logfile, 'w') as f:
f.write("Hello world\n")
Expand All @@ -111,7 +111,7 @@ def test_start_stop(self):

# Wait until input is stopped
self.wait_until(
lambda: self.log_contains("Stopping runner:"),
lambda: self.log_contains("Runner: 'input [type=log]' has stopped"),
max_timeout=15)

with open(logfile, 'a') as f:
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_start_stop_replace(self):

# Wait until input is stopped
self.wait_until(
lambda: self.log_contains("Stopping runner:"),
lambda: self.log_contains("Runner: 'input [type=log]' has stopped"),
max_timeout=15)

with open(self.working_dir + "/configs/input.yml", 'w') as f:
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_reload_same_input(self):

# Wait until input is stopped
self.wait_until(
lambda: self.log_contains("Stopping runner:"),
lambda: self.log_contains("Runner: 'input [type=log]' has stopped"),
max_timeout=15)

# Update both log files, only 1 change should be picked up
Expand Down Expand Up @@ -293,8 +293,6 @@ def test_load_configs(self):
assert output[0]["message"] == first_line
assert output[1]["message"] == second_line

# 1/20 build fails https://github.com/elastic/beats/issues/21307
@pytest.mark.flaky(reruns=2, reruns_delay=10)
def test_reload_same_config(self):
"""
Test reload same config with same file but different config. Makes sure reloading also works on conflicts.
Expand All @@ -310,7 +308,7 @@ def test_reload_same_config(self):
os.mkdir(self.working_dir + "/configs/")

with open(self.working_dir + "/configs/input.yml", 'w') as f:
f.write(inputConfigTemplate.format(self.working_dir + "/logs/*"))
f.write(inputConfigTemplate.format(self.working_dir + "/logs/*.log"))

proc = self.start_beat()

Expand Down
10 changes: 5 additions & 5 deletions filebeat/tests/system/test_reload_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_reload(self):
os.mkdir(self.working_dir + "/configs/")

with open(self.working_dir + "/configs/system.yml.test", 'w') as f:
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*"))
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*.log"))
os.rename(self.working_dir + "/configs/system.yml.test",
self.working_dir + "/configs/system.yml")

Expand Down Expand Up @@ -81,7 +81,7 @@ def test_reload_writes_pipeline(self):
os.mkdir(self.working_dir + "/configs/")

with open(self.working_dir + "/configs/system.yml.test", 'w') as f:
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*"))
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*.log"))
os.rename(self.working_dir + "/configs/system.yml.test",
self.working_dir + "/configs/system.yml")

Expand Down Expand Up @@ -109,7 +109,7 @@ def test_no_es_connection(self):

os.mkdir(self.working_dir + "/configs/")
with open(self.working_dir + "/configs/system.yml.test", 'w') as f:
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*"))
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*.log"))
os.rename(self.working_dir + "/configs/system.yml.test",
self.working_dir + "/configs/system.yml")

Expand All @@ -134,7 +134,7 @@ def test_start_stop(self):
os.mkdir(self.working_dir + "/configs/")

with open(self.working_dir + "/configs/system.yml.test", 'w') as f:
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*"))
f.write(moduleConfigTemplate.format(self.working_dir + "/logs/*.log"))
os.rename(self.working_dir + "/configs/system.yml.test",
self.working_dir + "/configs/system.yml")

Expand All @@ -150,7 +150,7 @@ def test_start_stop(self):

# Wait until input is stopped
self.wait_until(
lambda: self.log_contains("Stopping runner:"),
lambda: self.log_contains("Runner: 'test (test)' has stopped"),
max_timeout=15)

with open(logfile, 'a') as f:
Expand Down

0 comments on commit 5bdb7eb

Please sign in to comment.