diff --git a/changelog/812.feature b/changelog/812.feature new file mode 100644 index 00000000..4fda9541 --- /dev/null +++ b/changelog/812.feature @@ -0,0 +1 @@ +Partially restore old initial batch distribution algorithm in ``LoadScheduling``. diff --git a/src/xdist/scheduler/load.py b/src/xdist/scheduler/load.py index f32caa55..195282dc 100644 --- a/src/xdist/scheduler/load.py +++ b/src/xdist/scheduler/load.py @@ -248,13 +248,19 @@ def schedule(self): # Send a batch of tests to run. If we don't have at least two # tests per node, we have to send them all so that we can send # shutdown signals and get all nodes working. - initial_batch = max(len(self.pending) // 4, 2 * len(self.nodes)) - - # distribute tests round-robin up to the batch size - # (or until we run out) - nodes = cycle(self.nodes) - for i in range(initial_batch): - self._send_tests(next(nodes), 1) + if len(self.pending) < 2 * len(self.nodes): + # distribute tests round-robin + nodes = cycle(self.nodes) + for i in range(len(self.pending)): + self._send_tests(next(nodes), 1) + else: + # how many items per node do we have about? + items_per_node = len(self.collection) // len(self.node2pending) + # take a fraction of tests for initial distribution + node_chunksize = max(items_per_node // 4, 2) + # and initialize each node with a chunk of tests + for node in self.nodes: + self._send_tests(node, node_chunksize) if not self.pending: # initial distribution sent all tests, start node shutdown diff --git a/testing/test_dsession.py b/testing/test_dsession.py index d3a57152..86273b8c 100644 --- a/testing/test_dsession.py +++ b/testing/test_dsession.py @@ -115,18 +115,18 @@ def test_schedule_batch_size(self, pytester: pytest.Pytester) -> None: # assert not sched.tests_finished sent1 = node1.sent sent2 = node2.sent - assert sent1 == [0, 2] - assert sent2 == [1, 3] + assert sent1 == [0, 1] + assert sent2 == [2, 3] assert sched.pending == [4, 5] assert sched.node2pending[node1] == sent1 assert sched.node2pending[node2] == sent2 assert len(sched.pending) == 2 sched.mark_test_complete(node1, 0) - assert node1.sent == [0, 2, 4] + assert node1.sent == [0, 1, 4] assert sched.pending == [5] - assert node2.sent == [1, 3] - sched.mark_test_complete(node1, 2) - assert node1.sent == [0, 2, 4, 5] + assert node2.sent == [2, 3] + sched.mark_test_complete(node1, 1) + assert node1.sent == [0, 1, 4, 5] assert not sched.pending def test_schedule_fewer_tests_than_nodes(self, pytester: pytest.Pytester) -> None: