Docs written after the iterator is created are not visible.
(iter_collection)
| 212 | |
| 213 | |
| 214 | def 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 | |
| 249 | def test_iter_docs_snapshot_at_call_time(iter_collection): |