Agent: Add leading zero to single digits in worker thread names

This commit is contained in:
Mike Salvatore 2022-03-10 20:37:35 -05:00
parent 302718c4d4
commit 527c43a3f8
2 changed files with 7 additions and 7 deletions

View File

@ -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)

View File

@ -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