Configuration option for number of concurrent requests

This commit is contained in:
sebastien committed 2026-10-06 11:00:16 +02:00
1 parent 94ca8b8256
commit f43b713590
8 files changed
+151 -16

No files matched your search

+29 -2
View File
@@ -1,13 +1,13 @@
import io
import tempfile
import unittest
from concurrent.futures import wait as real_wait
from concurrent.futures import ThreadPoolExecutor, wait as real_wait
from contextlib import redirect_stdout
from pathlib import Path
from threading import Event
from unittest.mock import Mock, patch
from copienator import EvaluationWorkspace, ExitCode
from copienator import CliError, EvaluationWorkspace, ExitCode
from copienator.commands import gemini_for_labels as labels
@@ -36,6 +36,33 @@ class LabelTimeoutTests(unittest.TestCase):
sleep=lambda _: None, target_interval=0,
)
def test_cli_forwards_selected_concurrency(self):
for arguments, expected in (([], 12), (["--workers", "2"], 2)):
with self.subTest(arguments=arguments), \
patch.object(labels, "run", return_value=ExitCode.SUCCESS) as run:
self.assertEqual(labels.main([str(self.workspace.root), *arguments]), 0)
run.assert_called_once_with(
unittest.mock.ANY, [self.workspace.root],
overwrite=False, max_workers=expected,
)
def test_selected_concurrency_controls_executor(self):
self.client.models.generate_content.return_value = self.response
with patch.object(labels, "selected_images", return_value=(self.images, [])), \
patch.object(labels, "ThreadPoolExecutor", wraps=ThreadPoolExecutor) as executor:
result = labels.run(self.workspace, [], client=self.client,
sleep=lambda _: None, max_workers=1)
self.assertEqual(result, ExitCode.SUCCESS)
executor.assert_called_once_with(max_workers=1)
self.assertEqual(self.client.models.generate_content.call_count, 3)
def test_nonpositive_concurrency_rejected_before_requests(self):
for workers in (0, -1):
with self.subTest(workers=workers), self.assertRaises(CliError) as caught:
labels.run(self.workspace, [], client=self.client, max_workers=workers)
self.assertEqual(caught.exception.exit_code, ExitCode.INVALID_ARGUMENTS)
self.client.models.generate_content.assert_not_called()
def test_timeout_recovery_uses_bounded_requests_and_saves_result(self):
self.client.models.generate_content.side_effect = [TimeoutError(), self.response]
self.assertEqual(self.group(self.images[:1]), 1)