fix(agent): proxy gradio config and reduce translate blocking
This commit is contained in:
@@ -230,6 +230,32 @@ class TestProcessBatches:
|
||||
await executor._process_batches(run, job, batches, ["fr"])
|
||||
callback.assert_called_once()
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_process_batches_yields_after_commit(self, db_with_run):
|
||||
"""Regression: batch loop yields to event loop after sync DB commit."""
|
||||
session, run_id = db_with_run
|
||||
config = MagicMock()
|
||||
executor = TranslationExecutor(session, config)
|
||||
job = _make_job(session)
|
||||
run = session.query(TranslationRun).filter(TranslationRun.id == run_id).first()
|
||||
|
||||
batches = [
|
||||
[{"row_index": "0", "source_text": "Hello", "source_data": {"table": "t"}}],
|
||||
[{"row_index": "1", "source_text": "World", "source_data": {"table": "t"}}],
|
||||
]
|
||||
|
||||
with patch.object(executor, '_process_batch', new=AsyncMock(side_effect=[
|
||||
{"successful": 1, "failed": 0, "skipped": 0, "retries": 0, "cache_hits": 0, "batch_id": "batch-1"},
|
||||
{"successful": 1, "failed": 0, "skipped": 0, "retries": 0, "cache_hits": 0, "batch_id": "batch-2"},
|
||||
])):
|
||||
with patch.object(executor, '_insert_batch_to_target', new=AsyncMock(return_value=None)):
|
||||
with patch('src.plugins.translate.executor.asyncio.sleep', new=AsyncMock()) as mock_sleep:
|
||||
result = await executor._process_batches(run, job, batches, ["fr"])
|
||||
|
||||
assert result.status == "COMPLETED"
|
||||
assert mock_sleep.await_count == 2
|
||||
mock_sleep.assert_any_await(0)
|
||||
|
||||
|
||||
class TestFinalizeRun:
|
||||
"""Verify _finalize_run."""
|
||||
|
||||
Reference in New Issue
Block a user