MCPcopy Create free account
hub / github.com/alibaba/zvec / test_iter_docs_isolation

Function test_iter_docs_isolation

python/tests/test_iter_docs.py:214–246  ·  view source on GitHub ↗

Docs written after the iterator is created are not visible.

(iter_collection)

Source from the content-addressed store, hash-verified

212
213
214def test_iter_docs_isolation(iter_collection):
215 """Docs written after the iterator is created are not visible."""
216 iter_collection.insert(_make_docs(10))
217 iter_collection.flush()
218
219 it = iter_collection.iter_docs()
220 # Consume the first doc so the snapshot is established.
221 first = next(it)
222 assert first is not None
223
224 # Insert more docs after the iterator started. Writes are allowed while
225 # the iterator is open; exclusive schema operations are not (the
226 # active-iterator count rejects them), and the new docs are invisible
227 # to the snapshot either way.
228 iter_collection.insert(
229 [
230 Doc(
231 id=f"new_{i}",
232 fields={"id": 1000 + i, "name": "new", "weight": 1.0},
233 vectors={"dense": [1.0] * 8},
234 )
235 for i in range(5)
236 ]
237 )
238 with pytest.raises(RuntimeError):
239 iter_collection.destroy()
240
241 # Count remaining from the original snapshot (should be 9, total 10).
242 remaining = sum(1 for _ in it)
243 assert remaining == 9
244
245 # A fresh iterator sees all 15.
246 assert sum(1 for _ in iter_collection.iter_docs()) == 15
247
248
249def test_iter_docs_snapshot_at_call_time(iter_collection):

Callers

nothing calls this directly

Calls 6

DocClass · 0.90
iter_docsMethod · 0.80
_make_docsFunction · 0.70
insertMethod · 0.45
flushMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected