Skip to content

Commit b26a9d7

Browse files
Expand manager operation-name bounds coverage for fetch retry paths
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent f46e6c4 commit b26a9d7

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

tests/test_manager_operation_name_bounds.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,46 @@ def fake_collect_paginated_results(**kwargs):
9090
assert captured["poll_operation_name"].endswith("...")
9191

9292

93+
def test_sync_crawl_manager_bounds_operation_name_for_fetch_retry_path(monkeypatch):
94+
manager = sync_crawl_module.CrawlManager(_DummyClient())
95+
long_job_id = " \n" + ("x" * 500) + "\t"
96+
captured = {}
97+
98+
monkeypatch.setattr(
99+
manager,
100+
"start",
101+
lambda params: SimpleNamespace(job_id=long_job_id),
102+
)
103+
104+
def fake_poll_until_terminal_status(**kwargs):
105+
operation_name = kwargs["operation_name"]
106+
_assert_valid_operation_name(operation_name)
107+
captured["poll_operation_name"] = operation_name
108+
return "completed"
109+
110+
def fake_retry_operation(**kwargs):
111+
operation_name = kwargs["operation_name"]
112+
_assert_valid_operation_name(operation_name)
113+
captured["fetch_operation_name"] = operation_name
114+
return {"ok": True}
115+
116+
monkeypatch.setattr(
117+
sync_crawl_module,
118+
"poll_until_terminal_status",
119+
fake_poll_until_terminal_status,
120+
)
121+
monkeypatch.setattr(
122+
sync_crawl_module,
123+
"retry_operation",
124+
fake_retry_operation,
125+
)
126+
127+
result = manager.start_and_wait(params=object(), return_all_pages=False) # type: ignore[arg-type]
128+
129+
assert result == {"ok": True}
130+
assert captured["fetch_operation_name"] == captured["poll_operation_name"]
131+
132+
93133
def test_async_extract_manager_bounds_operation_name(monkeypatch):
94134
async def run() -> None:
95135
manager = async_extract_module.ExtractManager(_DummyClient())
@@ -166,3 +206,47 @@ async def fake_collect_paginated_results_async(**kwargs):
166206
assert captured["poll_operation_name"].endswith("...")
167207

168208
asyncio.run(run())
209+
210+
211+
def test_async_crawl_manager_bounds_operation_name_for_fetch_retry_path(monkeypatch):
212+
async def run() -> None:
213+
manager = async_crawl_module.CrawlManager(_DummyClient())
214+
long_job_id = " \n" + ("x" * 500) + "\t"
215+
captured = {}
216+
217+
async def fake_start(params):
218+
return SimpleNamespace(job_id=long_job_id)
219+
220+
async def fake_poll_until_terminal_status_async(**kwargs):
221+
operation_name = kwargs["operation_name"]
222+
_assert_valid_operation_name(operation_name)
223+
captured["poll_operation_name"] = operation_name
224+
return "completed"
225+
226+
async def fake_retry_operation_async(**kwargs):
227+
operation_name = kwargs["operation_name"]
228+
_assert_valid_operation_name(operation_name)
229+
captured["fetch_operation_name"] = operation_name
230+
return {"ok": True}
231+
232+
monkeypatch.setattr(manager, "start", fake_start)
233+
monkeypatch.setattr(
234+
async_crawl_module,
235+
"poll_until_terminal_status_async",
236+
fake_poll_until_terminal_status_async,
237+
)
238+
monkeypatch.setattr(
239+
async_crawl_module,
240+
"retry_operation_async",
241+
fake_retry_operation_async,
242+
)
243+
244+
result = await manager.start_and_wait(
245+
params=object(), # type: ignore[arg-type]
246+
return_all_pages=False,
247+
)
248+
249+
assert result == {"ok": True}
250+
assert captured["fetch_operation_name"] == captured["poll_operation_name"]
251+
252+
asyncio.run(run())

0 commit comments

Comments
 (0)