Larger chunk size based on worker count
@@ -3,6 +3,8 @@ import re
import subprocess
import string
import threading
+import itertools
+
from constants import TEST_CERT_DIRECTORY
from global_flags import get_flag, S2N_NO_PQ, S2N_FIPS_MODE
@@ -43,6 +45,9 @@ class AvailablePorts(object):
"""
def __init__(self, low=8000, high=30000):
+ worker_count = int(os.getenv('PYTEST_XDIST_WORKER_COUNT'))
+ chunk_size = int((high - low) / worker_count)
+
# If xdist is being used, parse the workerid from the envvar. This can
# be used to allocate unique ports to each worker.
worker = os.getenv('PYTEST_XDIST_WORKER')
@@ -54,7 +59,11 @@ class AvailablePorts(object):
# This is a naive way to allocate ports, but it allows us to cut
# the run time in half without workers colliding.
- self.ports = iter(range(low + (worker_id * 500), high))
+ worker_offset = (worker_id * chunk_size)
+ base_range = range(low + worker_offset, high)
+ wrap_range = range(low, low + worker_offset)
+ self.ports = iter(itertools.chain(base_range, wrap_range))
+
self.lock = threading.Lock()
def __iter__(self):
