From a5f9cc2d6101276d6629082f3c7eb1ed245bb67a Mon Sep 17 00:00:00 2001 From: jromnoa Date: Mon, 30 Aug 2021 17:56:23 -0700 Subject: [PATCH] use wait_for_condition() on newly created material cache files and wait for them to exist before continuing to prevent race condition Signed-off-by: jromnoa --- .../hydra_AtomMaterialEditor_BasicTests.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomMaterialEditor_BasicTests.py b/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomMaterialEditor_BasicTests.py index 130482cb99..9047b4c871 100644 --- a/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomMaterialEditor_BasicTests.py +++ b/AutomatedTesting/Gem/PythonTests/atom_renderer/atom_hydra_scripts/hydra_AtomMaterialEditor_BasicTests.py @@ -33,6 +33,7 @@ MATERIAL_TYPE_PATH = os.path.join( azlmbr.paths.devroot, "Gems", "Atom", "Feature", "Common", "Assets", "Materials", "Types", "StandardPBR.materialtype", ) +CACHE_FILE_EXTENSION = ".azmaterial" def run(): @@ -109,16 +110,22 @@ def run(): expected_color_1 = math.Color(0.5, 0.5, 0.5, 1.0) material_editor.set_property(document_id, property_name, expected_color_1) target_path_1 = os.path.join(azlmbr.paths.devroot, "AutomatedTesting", "Materials", NEW_MATERIAL_1) + cache_file_name_1 = os.path.splitext(NEW_MATERIAL_1) # Example output: ('test_material_1', '.material') + cache_file_1 = f"{cache_file_name_1[0]}{CACHE_FILE_EXTENSION}" + target_path_1_cache = os.path.join(azlmbr.paths.devassets, "Cache", "pc", "materials", cache_file_1) material_editor.save_document_as_copy(document_id, target_path_1) - time.sleep(2.0) + material_editor.wait_for_condition(lambda: os.path.exists(target_path_1_cache), 4.0) # 8) Test Case: Saving as a Child Material # Assign new color to the material file save the document as child expected_color_2 = math.Color(0.75, 0.75, 0.75, 1.0) material_editor.set_property(document_id, property_name, expected_color_2) target_path_2 = os.path.join(azlmbr.paths.devroot, "AutomatedTesting", "Materials", NEW_MATERIAL_2) + cache_file_name_2 = os.path.splitext(NEW_MATERIAL_1) # Example output: ('test_material_2', '.material') + cache_file_2 = f"{cache_file_name_2[0]}{CACHE_FILE_EXTENSION}" + target_path_2_cache = os.path.join(azlmbr.paths.devassets, "Cache", "pc", "materials", cache_file_2) material_editor.save_document_as_child(document_id, target_path_2) - time.sleep(2.0) + material_editor.wait_for_condition(lambda: os.path.exists(target_path_2_cache), 4.0) # Close/Reopen documents material_editor.close_all_documents()