feat: allow unrestricted independent job concurrency
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import hashlib
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import Mock, patch
|
||||
@@ -38,6 +39,82 @@ class SlowRescanSyncthing(CompleteSyncthing):
|
||||
|
||||
|
||||
class ClientJobHappyPathTests(unittest.TestCase):
|
||||
def test_reconnect_replay_never_duplicates_any_transfer_step(self):
|
||||
for step in (
|
||||
job_pb2.JOB_STEP_KIND_SOURCE_STAGE,
|
||||
job_pb2.JOB_STEP_KIND_SYNCTHING_TRANSFER,
|
||||
job_pb2.JOB_STEP_KIND_TARGET_MATERIALIZE,
|
||||
job_pb2.JOB_STEP_KIND_QB_VERIFY,
|
||||
job_pb2.JOB_STEP_KIND_STAGING_CLEANUP,
|
||||
):
|
||||
with self.subTest(step=step), tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
store = ClientStore(root / "client.db")
|
||||
store.initialize()
|
||||
definition = job_pb2.JobDefinition(
|
||||
job_id=str(uuid4()),
|
||||
idempotency_key=str(uuid4()),
|
||||
operation=job_pb2.JOB_OPERATION_ARCHIVE,
|
||||
resource_display_name="reconnect fixture",
|
||||
transfer={
|
||||
"source_client_id": "cache-1",
|
||||
"target_client_id": "archive-1",
|
||||
"route_id": "route-1",
|
||||
},
|
||||
)
|
||||
definition.resource_id.info_hash_v1_hex = "a" * 40
|
||||
definition.created_at.GetCurrentTime()
|
||||
executor = ClientJobExecutor(
|
||||
client_id="cache-1",
|
||||
qbittorrent=Mock(),
|
||||
store=store,
|
||||
qb_root=root,
|
||||
qb_api_root=Path("/downloads"),
|
||||
route_path=lambda _: root,
|
||||
syncthing_transport=Mock(),
|
||||
sparse_supported=True,
|
||||
)
|
||||
executor.assign(control_pb2.AssignJobCommand(
|
||||
job=definition,
|
||||
expected_job_revision=1,
|
||||
expected_last_event_sequence=0,
|
||||
))
|
||||
entered = threading.Event()
|
||||
release = threading.Event()
|
||||
|
||||
def execute_step(*_args):
|
||||
entered.set()
|
||||
release.wait(1)
|
||||
return None
|
||||
|
||||
executor._execute_step = Mock(side_effect=execute_step)
|
||||
command = control_pb2.ExecuteStepCommand(
|
||||
job_id=definition.job_id,
|
||||
expected_job_revision=1,
|
||||
expected_last_event_sequence=1,
|
||||
step=step,
|
||||
attempt=1,
|
||||
)
|
||||
results: list[list[control_pb2.JobEvent]] = []
|
||||
first = threading.Thread(
|
||||
target=lambda: results.append(executor.execute(command))
|
||||
)
|
||||
second = threading.Thread(
|
||||
target=lambda: results.append(executor.execute(command))
|
||||
)
|
||||
first.start()
|
||||
self.assertTrue(entered.wait(1))
|
||||
second.start()
|
||||
release.set()
|
||||
first.join(1)
|
||||
second.join(1)
|
||||
|
||||
self.assertFalse(first.is_alive())
|
||||
self.assertFalse(second.is_alive())
|
||||
self.assertEqual(executor._execute_step.call_count, 1)
|
||||
self.assertEqual(len(results), 2)
|
||||
self.assertEqual(results[0][-1].event_id, results[1][-1].event_id)
|
||||
|
||||
def test_capacity_guard_fails_before_data_movement(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
|
||||
Reference in New Issue
Block a user