From 3c9cac47060e49fa964b260917ece2768f8f1a76 Mon Sep 17 00:00:00 2001 From: anibalinn Date: Fri, 13 Sep 2024 19:36:00 -0300 Subject: [PATCH] Adding the --parallel-delay argument, to enable setting a staggered execution when running tests in parallel. --- CHANGES.rst | 3 ++- behavex/arguments.py | 5 +++++ behavex/runner.py | 8 ++++++-- setup.py | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 9877c43..5a203ec 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,11 +1,12 @@ Version History =============================================================================== -Version: 4.0.3 +Version: 4.0.4 ------------------------------------------------------------------------------- ENHANCEMENTS: * Added the 'worker_id' context.config.userdata parameter to allow users to identify which worker is executing every feature or scenario when running tests in parallel. `PR #121 `_ +* Adding the --parallel-delay argument, to enable setting a staggered execution when running tests in parallel. `Issue #142 `_ CONTRIBUTIONS: diff --git a/behavex/arguments.py b/behavex/arguments.py index 333dfd7..5d4feef 100644 --- a/behavex/arguments.py +++ b/behavex/arguments.py @@ -285,6 +285,11 @@ def parse_arguments(args): help="Specifies whether parallel execution should be performed at the scenario or feature level.", required=False, ) + parser.add_argument( + '--parallel-delay', + type=int, + default=0, + help='Delay in milliseconds before starting each parallel process') parser.add_argument( '-ip', '--include-paths', diff --git a/behavex/runner.py b/behavex/runner.py index 631f0c9..50584e2 100644 --- a/behavex/runner.py +++ b/behavex/runner.py @@ -167,13 +167,16 @@ def setup_running_failures(args_parsed): return EXIT_OK, None -def init_multiprocessing(idQueue): +def init_multiprocessing(idQueue, parallel_delay): """Initialize multiprocessing by ignoring SIGINT signals.""" signal.signal(signal.SIGINT, signal.SIG_IGN) # Retrieve one of the unique IDs worker_id = idQueue.get() # Use the unique ID to name the process multiprocessing.current_process().name = f'behave_worker-{worker_id}' + # Add delay + if parallel_delay > 0: + time.sleep(parallel_delay / 1000.0) def launch_behavex(): @@ -217,9 +220,10 @@ def launch_behavex(): idQueue = manager.Queue() for i in range(parallel_processes): idQueue.put(i) + parallel_delay = get_param('parallel_delay') process_pool = ProcessPoolExecutor(max_workers=parallel_processes, initializer=init_multiprocessing, - initargs=(idQueue,)) + initargs=(idQueue, parallel_delay)) global_vars.execution_start_time = time.time() try: config = ConfigRun() diff --git a/setup.py b/setup.py index 249bc91..82ff1c1 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='behavex', - version='4.0.2', + version='4.0.4rc1', license="MIT", platforms=['any'], python_requires='>=3.5',