fix(workbench): serialize events and target work order sync
This commit is contained in:
@@ -42,12 +42,25 @@ class PushStream(httpx.AsyncByteStream):
|
||||
)
|
||||
|
||||
|
||||
def test_large_source_burst_coalesces_to_full_reconciliation_with_bounded_ids():
|
||||
settings = WorkerSettings("http://server.test", "http://agent.test", str(uuid4()), bearer="TEST_ONLY")
|
||||
synchronizer = PeripheralWorkOrderSynchronizer(None, settings, "http://sample.test", CredentialProvider(settings))
|
||||
order_id = str(uuid4())
|
||||
for _ in range(1000):
|
||||
synchronizer._queue_order(order_id)
|
||||
assert synchronizer.pending_order_ids == {order_id}
|
||||
for _ in range(1000):
|
||||
synchronizer._queue_order(str(uuid4()))
|
||||
assert synchronizer.full_reconcile
|
||||
assert synchronizer.pending_order_ids == set()
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_source_push_synchronizes_new_and_updated_orders_without_waiting_for_reconciliation():
|
||||
project_id, order_id, task_id = map(str, (uuid4(), uuid4(), uuid4()))
|
||||
settings = WorkerSettings("http://server.test", "http://agent.test", project_id, bearer="TEST_ONLY")
|
||||
stream = PushStream()
|
||||
orders, tasks, cursors = [], [], []
|
||||
orders, tasks, cursors, task_queries = [], [], [], []
|
||||
initial_scan, projected = asyncio.Event(), asyncio.Event()
|
||||
scan_count = 0
|
||||
|
||||
@@ -63,8 +76,11 @@ async def test_source_push_synchronizes_new_and_updated_orders_without_waiting_f
|
||||
if request.url.host == "sample.test":
|
||||
scan_count += 1
|
||||
initial_scan.set()
|
||||
if request.url.path.endswith(f"/work-orders/{order_id}"):
|
||||
return httpx.Response(200, json=orders[0])
|
||||
return httpx.Response(200, json={"items": orders, "next_cursor": None})
|
||||
if request.method == "GET":
|
||||
task_queries.append(dict(request.url.params))
|
||||
return httpx.Response(200, json={"items": tasks, "next_offset": None})
|
||||
body = json.loads(request.content)
|
||||
if request.url.path.endswith("external-feedback"):
|
||||
@@ -100,6 +116,8 @@ async def test_source_push_synchronizes_new_and_updated_orders_without_waiting_f
|
||||
assert tasks[0]["source"]["external_revision"] == 2
|
||||
assert tasks[0]["status"] == "in_progress"
|
||||
assert scan_count == 3 # Startup plus two pushed source changes.
|
||||
assert task_queries[0] == {"limit": "100", "offset": "0"}
|
||||
assert all(query["peripheral_work_order_id"] == order_id for query in task_queries[1:])
|
||||
assert cursors == ["20"]
|
||||
finally:
|
||||
runner.cancel()
|
||||
@@ -221,7 +239,7 @@ async def test_failed_scan_retries_without_requiring_another_source_message(monk
|
||||
return httpx.Response(200, json={"event_cursor": 20})
|
||||
return httpx.Response(200, stream=stream)
|
||||
|
||||
async def sync_once(*_args):
|
||||
async def sync_once(*_args, **_kwargs):
|
||||
nonlocal attempts
|
||||
attempts += 1
|
||||
if attempts == 1:
|
||||
@@ -256,13 +274,14 @@ async def test_source_event_during_scan_schedules_another_pass(monkeypatch):
|
||||
return httpx.Response(200, json={"event_cursor": 20})
|
||||
return httpx.Response(200, stream=stream)
|
||||
|
||||
async def sync_once(*_args):
|
||||
async def sync_once(*_args, **kwargs):
|
||||
nonlocal attempts
|
||||
attempts += 1
|
||||
if attempts == 1:
|
||||
scanning.set()
|
||||
await release.wait()
|
||||
else:
|
||||
assert kwargs["work_order_ids"] == {order_id}
|
||||
caught_up.set()
|
||||
return 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user