Skip to content

Commit b02b7ce

Browse files
test: adding mixing filter async tests + implementing them in InMemoryDocumentStore tests (#10975)
1 parent 873523c commit b02b7ce

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

haystack/testing/document_store_async.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from haystack.dataclasses import Document
1111
from haystack.document_stores.errors import DuplicateDocumentError
1212
from haystack.document_stores.types import DocumentStore, DuplicatePolicy
13-
from haystack.testing.document_store import AssertDocumentsEqualMixin
13+
from haystack.testing.document_store import AssertDocumentsEqualMixin, FilterableDocsFixtureMixin
1414

1515

1616
class AsyncDocumentStore(DocumentStore, Protocol):
@@ -550,3 +550,49 @@ async def test_get_metadata_field_unique_values_basic_async(document_store: Asyn
550550
assert set(values) == {"A", "B", "C"}
551551
if isinstance(result, tuple) and len(result) >= 2 and isinstance(result[1], int):
552552
assert result[1] == 3
553+
554+
555+
class FilterDocumentsAsyncTest(AssertDocumentsEqualMixin, FilterableDocsFixtureMixin):
556+
"""
557+
Smoke tests for the async filter_documents_async() path.
558+
559+
These tests verify that the async plumbing works correctly with no filters,
560+
a simple equality filter, and a compound AND filter. Full filter logic correctness
561+
is covered by FilterDocumentsTest — the sync and async paths share the same
562+
filter translation layer, so only the async dispatch needs smoke-testing here.
563+
"""
564+
565+
@staticmethod
566+
@pytest.mark.asyncio
567+
async def test_no_filters_async(document_store: AsyncDocumentStore):
568+
"""Verify the async path returns all documents when no filter is applied."""
569+
docs = [Document(content="first doc"), Document(content="second doc"), Document(content="third doc")]
570+
await document_store.write_documents_async(docs)
571+
result = await document_store.filter_documents_async()
572+
assert len(result) == 3
573+
574+
@pytest.mark.asyncio
575+
async def test_filter_simple_async(self, document_store: AsyncDocumentStore, filterable_docs: list[Document]):
576+
"""One equality filter — confirms async plumbing works with a filter."""
577+
await document_store.write_documents_async(filterable_docs)
578+
result = await document_store.filter_documents_async(
579+
filters={"field": "meta.number", "operator": "==", "value": 2}
580+
)
581+
self.assert_documents_are_equal(result, [d for d in filterable_docs if d.meta.get("number") == 2])
582+
583+
@pytest.mark.asyncio
584+
async def test_filter_compound_async(self, document_store: AsyncDocumentStore, filterable_docs: list[Document]):
585+
"""One AND filter — verifies compound filters aren't broken by the async path."""
586+
await document_store.write_documents_async(filterable_docs)
587+
result = await document_store.filter_documents_async(
588+
filters={
589+
"operator": "AND",
590+
"conditions": [
591+
{"field": "meta.number", "operator": "==", "value": 2},
592+
{"field": "meta.name", "operator": "==", "value": "name_0"},
593+
],
594+
}
595+
)
596+
self.assert_documents_are_equal(
597+
result, [d for d in filterable_docs if d.meta.get("number") == 2 and d.meta.get("name") == "name_0"]
598+
)

test/document_stores/test_in_memory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from haystack.testing.document_store_async import (
3030
CountDocumentsAsyncTest,
3131
DeleteDocumentsAsyncTest,
32+
FilterDocumentsAsyncTest,
3233
GetMetadataFieldMinMaxAsyncTest,
3334
GetMetadataFieldsInfoAsyncTest,
3435
GetMetadataFieldUniqueValuesAsyncTest,
@@ -46,6 +47,7 @@ class TestMemoryDocumentStore(
4647
CountDocumentsByFilterTest,
4748
CountUniqueMetadataByFilterAsyncTest,
4849
CountUniqueMetadataByFilterTest,
50+
FilterDocumentsAsyncTest,
4951
FilterableDocsFixtureMixin,
5052
GetMetadataFieldMinMaxTest,
5153
GetMetadataFieldUniqueValuesTest,

0 commit comments

Comments
 (0)