From 527c43a3f868b1f8143c730a52d99d9be5a96b4d Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 10 Mar 2022 20:37:35 -0500 Subject: [PATCH] Agent: Add leading zero to single digits in worker thread names --- monkey/infection_monkey/utils/threading.py | 2 +- .../infection_monkey/utils/test_threading.py | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/monkey/infection_monkey/utils/threading.py b/monkey/infection_monkey/utils/threading.py index 70f48bbe9..e383a2ee9 100644 --- a/monkey/infection_monkey/utils/threading.py +++ b/monkey/infection_monkey/utils/threading.py @@ -15,7 +15,7 @@ def run_worker_threads( worker_threads = [] counter = run_worker_threads.counters.setdefault(name_prefix, count(start=1)) for i in range(0, num_workers): - name = f"{name_prefix}-{next(counter)}" + name = f"{name_prefix}-{next(counter):02d}" t = create_daemon_thread(target=target, name=name, args=args) t.start() worker_threads.append(t) diff --git a/monkey/tests/unit_tests/infection_monkey/utils/test_threading.py b/monkey/tests/unit_tests/infection_monkey/utils/test_threading.py index 915099f04..6d1e759c8 100644 --- a/monkey/tests/unit_tests/infection_monkey/utils/test_threading.py +++ b/monkey/tests/unit_tests/infection_monkey/utils/test_threading.py @@ -66,10 +66,10 @@ def test_worker_thread_names(): run_worker_threads(target=add_thread_name_to_list, name_prefix="B", num_workers=2) run_worker_threads(target=add_thread_name_to_list, name_prefix="A", num_workers=2) - assert "A-1" in thread_names - assert "A-2" in thread_names - assert "A-3" in thread_names - assert "A-4" in thread_names - assert "B-1" in thread_names - assert "B-2" in thread_names + assert "A-01" in thread_names + assert "A-02" in thread_names + assert "A-03" in thread_names + assert "A-04" in thread_names + assert "B-01" in thread_names + assert "B-02" in thread_names assert len(thread_names) == 6