From 0a8d9c38c07c2255ce7c60dae2ba9c138f1557f1 Mon Sep 17 00:00:00 2001 From: Aleksey Nogin Date: Wed, 5 Jun 2024 19:32:42 -0700 Subject: [PATCH] Fix an issue with parallel tests potentially clashing (#468) * Fix an issue with parallel tests potentially clashing * Run pre-commit --- ofrak_core/requirements-test.txt | 1 + .../components/test_patch_maker_component.py | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ofrak_core/requirements-test.txt b/ofrak_core/requirements-test.txt index 977de5a37..71aba2382 100644 --- a/ofrak_core/requirements-test.txt +++ b/ofrak_core/requirements-test.txt @@ -1,6 +1,7 @@ autoflake==1.4 # pytest-lazy-fixture does not work with pytest 8.0.0 - https://github.com/TvoroG/pytest-lazy-fixture/issues/65 pytest<8.0 +filelock hypothesis~=6.39.3 hypothesis-trio trio-asyncio diff --git a/ofrak_core/test_ofrak/components/test_patch_maker_component.py b/ofrak_core/test_ofrak/components/test_patch_maker_component.py index d36c8c239..f35507324 100644 --- a/ofrak_core/test_ofrak/components/test_patch_maker_component.py +++ b/ofrak_core/test_ofrak/components/test_patch_maker_component.py @@ -5,6 +5,7 @@ import pytest import re import subprocess +import filelock from ofrak.core import MemoryRegion from ofrak.model.resource_model import EphemeralResourceContextFactory, ClientResourceContextFactory @@ -230,19 +231,23 @@ async def test_function_replacement_modifier(ofrak_context: OFRAKContext, config await target_program.resource.run(FunctionReplacementModifier, function_replacement_config) new_program_path = f"replaced_{Path(config.program.path).name}" - await target_program.resource.flush_data_to_disk(new_program_path) - # Check that the modified program looks as expected. - readobj_path = get_repository_config(config.toolchain_name, "BIN_PARSER") + # When running tests in parallel, do this one at a time + lock = filelock.FileLock(new_program_path + ".lock") + with lock: + await target_program.resource.flush_data_to_disk(new_program_path) - # LLVM-specific fix: use llvm-objdump, not llvm-readobj - if "readobj" in readobj_path: - readobj_path = readobj_path.replace("readobj", "objdump") + # Check that the modified program looks as expected. + readobj_path = get_repository_config(config.toolchain_name, "BIN_PARSER") - subprocess_result = subprocess.run( - [readobj_path, "-d", new_program_path], capture_output=True, text=True - ) - readobj_output = subprocess_result.stdout + # LLVM-specific fix: use llvm-objdump, not llvm-readobj + if "readobj" in readobj_path: + readobj_path = readobj_path.replace("readobj", "objdump") + + subprocess_result = subprocess.run( + [readobj_path, "-d", new_program_path], capture_output=True, text=True + ) + readobj_output = subprocess_result.stdout expected_objdump_output_str = "\n".join(config.expected_objdump_output)