|
12 | 12 |
|
13 | 13 | import pytest |
14 | 14 |
|
15 | | -from api.search import _resolve_search_results, _search_via_index |
| 15 | +from api.search import ( |
| 16 | + _live_scan_with_index_lock_fallback, |
| 17 | + _merge_search_hits, |
| 18 | + _resolve_search_results, |
| 19 | + _search_via_index, |
| 20 | +) |
16 | 21 | from tests.conftest import index_patches as _index_patches, write_session as _write_session |
17 | 22 | from utils.search_index import ( |
18 | 23 | IndexQueryResult, |
@@ -371,14 +376,41 @@ def test_index_locked_without_hits_falls_back_to_live_scan(self, indexed_tree) - |
371 | 376 | patches[0], |
372 | 377 | patch("api.search.query_index_hits", return_value=_LOCKED_PAYLOAD), |
373 | 378 | ): |
374 | | - hits = _resolve_search_results( |
| 379 | + outcome = _search_via_index( |
375 | 380 | indexed_tree["projects"], |
376 | 381 | [], |
377 | 382 | indexed_tree["term"], |
378 | 383 | indexed_tree["term"], |
379 | 384 | since_ms=None, |
380 | 385 | max_results=50, |
381 | 386 | ) |
| 387 | + assert outcome.hits is None |
| 388 | + assert outcome.index_locked_without_hits is True |
| 389 | + |
| 390 | + lock_fallback_flags: list[bool] = [] |
| 391 | + |
| 392 | + def _record_lock_fallback(*args: object, **kwargs: object) -> list[object]: |
| 393 | + lock_fallback_flags.append(bool(kwargs["index_locked_without_hits"])) |
| 394 | + return _live_scan_with_index_lock_fallback(*args, **kwargs) |
| 395 | + |
| 396 | + with ( |
| 397 | + patch( |
| 398 | + "api.search._live_scan_with_index_lock_fallback", |
| 399 | + side_effect=_record_lock_fallback, |
| 400 | + ), |
| 401 | + patch("api.search._merge_search_hits", wraps=_merge_search_hits) as merge_mock, |
| 402 | + ): |
| 403 | + hits = _resolve_search_results( |
| 404 | + indexed_tree["projects"], |
| 405 | + [], |
| 406 | + indexed_tree["term"], |
| 407 | + indexed_tree["term"], |
| 408 | + since_ms=None, |
| 409 | + max_results=50, |
| 410 | + ) |
| 411 | + |
| 412 | + assert lock_fallback_flags == [True] |
| 413 | + merge_mock.assert_not_called() |
382 | 414 | assert len(hits) >= 1 |
383 | 415 |
|
384 | 416 | def test_search_via_index_returns_partial_hits_when_locked_after_batch( |
|
0 commit comments