@@ -83,6 +83,14 @@ def indexed_tree(tmp_path, monkeypatch):
8383 }
8484
8585
86+ def _sentinel_hit_observed (term : str , result : IndexQueryResult ) -> bool :
87+ if result ["index_locked" ] or not result ["query_ok" ]:
88+ return False
89+ if not result ["hits" ]:
90+ return False
91+ return any (term in (hit ["text" ] or "" ) for hit in result ["hits" ])
92+
93+
8694def _assert_sentinel_reader_result (term : str , result : IndexQueryResult ) -> None :
8795 if result ["index_locked" ]:
8896 return
@@ -168,8 +176,11 @@ def test_concurrent_rebuild_and_query(self, indexed_tree) -> None:
168176 errors : list [BaseException ] = []
169177 barrier = threading .Barrier (_READER_THREADS + 1 , timeout = _BARRIER_TIMEOUT_S )
170178 patches = _index_patches (indexed_tree ["cache_root" ])
179+ hits_lock = threading .Lock ()
180+ sentinel_hits_observed = 0
171181
172182 def reader () -> None :
183+ nonlocal sentinel_hits_observed
173184 try :
174185 for _ in range (_CONCURRENT_ROUNDS ):
175186 barrier .wait (timeout = _BARRIER_TIMEOUT_S )
@@ -179,6 +190,9 @@ def reader() -> None:
179190 max_results = 10 ,
180191 )
181192 _assert_sentinel_reader_result (indexed_tree ["term" ], result )
193+ if _sentinel_hit_observed (indexed_tree ["term" ], result ):
194+ with hits_lock :
195+ sentinel_hits_observed += 1
182196 except BaseException as exc :
183197 errors .append (exc )
184198
@@ -201,6 +215,9 @@ def writer() -> None:
201215 thread .join (timeout = _BARRIER_TIMEOUT_S + 90.0 )
202216 assert not thread .is_alive (), f"{ thread .name } did not finish (possible deadlock)"
203217 assert not errors , errors
218+ assert sentinel_hits_observed > 0 , (
219+ "no reader round observed sentinel hits during concurrent rebuild"
220+ )
204221
205222 def test_queries_during_background_refresh (self , indexed_tree ) -> None :
206223 errors : list [BaseException ] = []
0 commit comments