Skip to content

Commit

Permalink
Adding the --parallel-delay argument, to enable setting a staggered e…
Browse files Browse the repository at this point in the history
…xecution when running tests in parallel.
  • Loading branch information
anibalinn committed Sep 13, 2024
1 parent 7899558 commit 3c9cac4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/hrcorval/behavex/pull/121>`_
* Adding the --parallel-delay argument, to enable setting a staggered execution when running tests in parallel. `Issue #142 <https://github.com/hrcorval/behavex/issues/142>`_

CONTRIBUTIONS:

Expand Down
5 changes: 5 additions & 0 deletions behavex/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 6 additions & 2 deletions behavex/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='behavex',
version='4.0.2',
version='4.0.4rc1',
license="MIT",
platforms=['any'],
python_requires='>=3.5',
Expand Down

0 comments on commit 3c9cac4

Please sign in to comment.