From 4c1fef54bbb36f4e175ab64ac92985c968fc5cac Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Tue, 11 Jun 2024 14:04:14 +0530 Subject: [PATCH 1/5] fix: fix a flaky test on macos --- filebeat/tests/system/test_shutdown.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/filebeat/tests/system/test_shutdown.py b/filebeat/tests/system/test_shutdown.py index 8f18337435f..d584213cb6b 100644 --- a/filebeat/tests/system/test_shutdown.py +++ b/filebeat/tests/system/test_shutdown.py @@ -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") From a16d92b7073b2b4dbea6c012e6bec71115d8bb93 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Tue, 11 Jun 2024 18:53:20 +0530 Subject: [PATCH 2/5] fix: fix more such test cases --- filebeat/tests/system/test_crawler.py | 4 ++-- filebeat/tests/system/test_harvester.py | 2 +- filebeat/tests/system/test_registrar.py | 18 +++++++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/filebeat/tests/system/test_crawler.py b/filebeat/tests/system/test_crawler.py index 2bea57223fe..39f0d454124 100644 --- a/filebeat/tests/system/test_crawler.py +++ b/filebeat/tests/system/test_crawler.py @@ -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 @@ -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: diff --git a/filebeat/tests/system/test_harvester.py b/filebeat/tests/system/test_harvester.py index 3b40f3a6730..9099abc699e 100644 --- a/filebeat/tests/system/test_harvester.py +++ b/filebeat/tests/system/test_harvester.py @@ -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() diff --git a/filebeat/tests/system/test_registrar.py b/filebeat/tests/system/test_registrar.py index 53af186dbf9..f41098f3beb 100644 --- a/filebeat/tests/system/test_registrar.py +++ b/filebeat/tests/system/test_registrar.py @@ -254,7 +254,7 @@ def test_registry_file_update_permissions(self): 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 ) @@ -269,7 +269,7 @@ def test_registry_file_update_permissions(self): max_timeout=1) # Wait a moment to make sure registry is completely written - time.sleep(1) + time.sleep(10) filebeat.check_kill_and_wait() @@ -975,8 +975,8 @@ def test_restart_state_reset(self): self.render_config_template( path=os.path.abspath(self.working_dir) + "/log/*", - clean_inactive="10s", - ignore_older="5s" + clean_inactive="20s", + ignore_older="10s" ) os.mkdir(self.working_dir + "/log/") @@ -1002,8 +1002,8 @@ def test_restart_state_reset(self): # No config file which does not match the existing state self.render_config_template( path=os.path.abspath(self.working_dir) + "/log/test2.log", - clean_inactive="10s", - ignore_older="5s", + clean_inactive="20s", + ignore_older="10s", ) filebeat = self.start_beat(output="filebeat2.log") @@ -1136,8 +1136,8 @@ 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" + clean_inactive="20s", + ignore_older="10s" ) os.mkdir(self.working_dir + "/log/") @@ -1158,7 +1158,7 @@ def test_restart_state_reset_ttl_no_clean_inactive(self): # Check that ttl > 0 was set because of clean_inactive data = self.get_registry() assert len(data) == 1 - assert data[0]["ttl"] == 10 * 1000 * 1000 * 1000 + assert data[0]["ttl"] == 20 * 1000 * 1000 * 1000 # New config without clean_inactive self.render_config_template( From bd2b06d5beb8403e4a991a323a56462aed840bd8 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Wed, 12 Jun 2024 16:31:36 +0530 Subject: [PATCH 3/5] fix: only update ignore_older --- filebeat/tests/system/test_registrar.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/filebeat/tests/system/test_registrar.py b/filebeat/tests/system/test_registrar.py index f41098f3beb..99fbfa26e63 100644 --- a/filebeat/tests/system/test_registrar.py +++ b/filebeat/tests/system/test_registrar.py @@ -252,6 +252,8 @@ 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=registry_home, @@ -266,10 +268,10 @@ 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(10) + time.sleep(1) filebeat.check_kill_and_wait() @@ -975,8 +977,8 @@ def test_restart_state_reset(self): self.render_config_template( path=os.path.abspath(self.working_dir) + "/log/*", - clean_inactive="20s", - ignore_older="10s" + clean_inactive="10s", + ignore_older="9s" ) os.mkdir(self.working_dir + "/log/") @@ -1002,8 +1004,8 @@ def test_restart_state_reset(self): # No config file which does not match the existing state self.render_config_template( path=os.path.abspath(self.working_dir) + "/log/test2.log", - clean_inactive="20s", - ignore_older="10s", + clean_inactive="10s", + ignore_older="9s", ) filebeat = self.start_beat(output="filebeat2.log") @@ -1136,8 +1138,8 @@ 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="20s", - ignore_older="10s" + clean_inactive="10s", + ignore_older="9s" ) os.mkdir(self.working_dir + "/log/") @@ -1158,7 +1160,7 @@ def test_restart_state_reset_ttl_no_clean_inactive(self): # Check that ttl > 0 was set because of clean_inactive data = self.get_registry() assert len(data) == 1 - assert data[0]["ttl"] == 20 * 1000 * 1000 * 1000 + assert data[0]["ttl"] == 10 * 1000 * 1000 * 1000 # New config without clean_inactive self.render_config_template( From b53cccbcb76b50f6a3892abb9965b0217f474974 Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Wed, 12 Jun 2024 17:19:21 +0530 Subject: [PATCH 4/5] fix: also fix flaky test_restart_state --- filebeat/tests/system/test_registrar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filebeat/tests/system/test_registrar.py b/filebeat/tests/system/test_registrar.py index 99fbfa26e63..b08eda2777c 100644 --- a/filebeat/tests/system/test_registrar.py +++ b/filebeat/tests/system/test_registrar.py @@ -952,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() From 3ea3e33a7a3b335ac1cb48ceeaaf009f8049684b Mon Sep 17 00:00:00 2001 From: Vihas Makwana Date: Wed, 12 Jun 2024 19:22:00 +0530 Subject: [PATCH 5/5] fix: fix CI --- filebeat/tests/system/test_shutdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filebeat/tests/system/test_shutdown.py b/filebeat/tests/system/test_shutdown.py index d584213cb6b..8e781837730 100644 --- a/filebeat/tests/system/test_shutdown.py +++ b/filebeat/tests/system/test_shutdown.py @@ -30,7 +30,7 @@ def test_shutdown(self): # 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" : + if platform.system() == "Darwin": time.sleep(10) else: time.sleep(.5)