From 2f5f787f65953e607136982c905b1aed5bcb02e9 Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Tue, 26 Nov 2019 01:08:17 +0000 Subject: [PATCH 1/3] Less flaky retry tests --- .../files/file/base/retry/retry_success.sls | 4 ++-- .../files/file/base/retry/retry_success2.sls | 11 ++++++++-- tests/integration/modules/test_state.py | 20 ++++++++++++------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/integration/files/file/base/retry/retry_success.sls b/tests/integration/files/file/base/retry/retry_success.sls index 7497d14f194..b0b3c83d4e1 100644 --- a/tests/integration/files/file/base/retry/retry_success.sls +++ b/tests/integration/files/file/base/retry/retry_success.sls @@ -1,10 +1,10 @@ -{{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file') }}: +{{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file_option_succeess') }}: file: - touch file_test: file.exists: - - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file') }} + - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file_option_success') }} - retry: until: True attempts: 5 diff --git a/tests/integration/files/file/base/retry/retry_success2.sls b/tests/integration/files/file/base/retry/retry_success2.sls index daa08c5e008..9fefb2cef46 100644 --- a/tests/integration/files/file/base/retry/retry_success2.sls +++ b/tests/integration/files/file/base/retry/retry_success2.sls @@ -1,7 +1,14 @@ -file_test: +file_test_a: + file.managed: + - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file_eventual_success') + '_a' }} + - content: 'a' + +file_test_b: file.exists: - - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file') }} + - name: {{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file_eventual_success') }} - retry: until: True attempts: 20 interval: 5 + - require: + - file_test_a diff --git a/tests/integration/modules/test_state.py b/tests/integration/modules/test_state.py index 6c9ae55c9ef..c086323bf13 100644 --- a/tests/integration/modules/test_state.py +++ b/tests/integration/modules/test_state.py @@ -1764,7 +1764,7 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin): ''' test a state with the retry option that should return True immedietly (i.e. no retries) ''' - testfile = os.path.join(TMP, 'retry_file') + testfile = os.path.join(TMP, 'retry_file_option_success') state_run = self.run_function( 'state.sls', mods='retry.retry_success' @@ -1773,29 +1773,35 @@ class StateModuleTest(ModuleCase, SaltReturnAssertsMixin): retry_state = 'file_|-file_test_|-{0}_|-exists'.format(testfile) self.assertNotIn('Attempt', state_run[retry_state]['comment']) - def run_create(self): + def run_create(self, testfile): ''' helper function to wait 30 seconds and then create the temp retry file ''' - testfile = os.path.join(TMP, 'retry_file') + # Wait for the requisite stae 'file_test_a' to complete before creating + # test_file + while True: + if os.path.exists(testfile + '_a'): + break + time.sleep(1) time.sleep(30) with salt.utils.files.fopen(testfile, 'a'): pass - @flaky def test_retry_option_eventual_success(self): ''' test a state with the retry option that should return True after at least 4 retry attmempt but never run 15 attempts ''' - testfile = os.path.join(TMP, 'retry_file') - create_thread = threading.Thread(target=self.run_create) + testfile = os.path.join(TMP, 'retry_file_eventual_success') + assert not os.path.exists(testfile + '_a') + assert not os.path.exists(testfile) + create_thread = threading.Thread(target=self.run_create, args=(testfile,)) create_thread.start() state_run = self.run_function( 'state.sls', mods='retry.retry_success2' ) - retry_state = 'file_|-file_test_|-{0}_|-exists'.format(testfile) + retry_state = 'file_|-file_test_b_|-{0}_|-exists'.format(testfile) self.assertIn('Attempt 1:', state_run[retry_state]['comment']) self.assertIn('Attempt 2:', state_run[retry_state]['comment']) self.assertIn('Attempt 3:', state_run[retry_state]['comment']) From 60b4db3ac1ba5666f5869f61e6f2d8a92991130f Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Tue, 26 Nov 2019 05:21:10 +0000 Subject: [PATCH 2/3] Fix un-used import --- tests/integration/modules/test_state.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/modules/test_state.py b/tests/integration/modules/test_state.py index c086323bf13..ee32b1f1d99 100644 --- a/tests/integration/modules/test_state.py +++ b/tests/integration/modules/test_state.py @@ -13,7 +13,7 @@ import time # Import Salt Testing libs from tests.support.case import ModuleCase -from tests.support.helpers import with_tempdir, flaky +from tests.support.helpers import with_tempdir from tests.support.unit import skipIf from tests.support.paths import BASE_FILES, TMP, TMP_PILLAR_TREE, TMP_STATE_TREE from tests.support.mixins import SaltReturnAssertsMixin From 4448514b1d928c892b5a64174699e00e16f53c2d Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Tue, 26 Nov 2019 05:24:11 +0000 Subject: [PATCH 3/3] Fix typo --- tests/integration/files/file/base/retry/retry_success.sls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/files/file/base/retry/retry_success.sls b/tests/integration/files/file/base/retry/retry_success.sls index b0b3c83d4e1..f7cddb5f000 100644 --- a/tests/integration/files/file/base/retry/retry_success.sls +++ b/tests/integration/files/file/base/retry/retry_success.sls @@ -1,4 +1,4 @@ -{{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file_option_succeess') }}: +{{ salt['runtests_helpers.get_salt_temp_dir_for_path']('retry_file_option_success') }}: file: - touch