mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-06-26 22:00:13 +00:00
ci: prevent DocumentWriter tests from blocking CI (#9448)
This commit is contained in:
parent
d8487c4d8d
commit
085c3add41
@ -126,7 +126,5 @@ class DocumentWriter:
|
||||
if not hasattr(self.document_store, "write_documents_async"):
|
||||
raise TypeError(f"Document store {type(self.document_store).__name__} does not provide async support.")
|
||||
|
||||
documents_written = await self.document_store.write_documents_async( # type: ignore
|
||||
documents=documents, policy=policy
|
||||
)
|
||||
documents_written = await self.document_store.write_documents_async(documents=documents, policy=policy)
|
||||
return {"documents_written": documents_written}
|
||||
|
@ -11,6 +11,19 @@ from haystack.document_stores.types import DuplicatePolicy
|
||||
from haystack.document_stores.in_memory import InMemoryDocumentStore
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def document_store():
|
||||
"""
|
||||
Create a fresh InMemoryDocumentStore for each test with proper cleanup.
|
||||
|
||||
Using a fixture ensures the ThreadPoolExecutor is shut down immediately after test completion rather than
|
||||
during (unpredictable) garbage collection, which can make the CI hang.
|
||||
"""
|
||||
store = InMemoryDocumentStore()
|
||||
yield store
|
||||
store.shutdown()
|
||||
|
||||
|
||||
class TestDocumentWriter:
|
||||
def test_to_dict(self):
|
||||
mocked_docstore_class = document_store_class("MockedDocumentStore")
|
||||
@ -69,8 +82,7 @@ class TestDocumentWriter:
|
||||
with pytest.raises(DeserializationError):
|
||||
DocumentWriter.from_dict(data)
|
||||
|
||||
def test_run(self):
|
||||
document_store = InMemoryDocumentStore()
|
||||
def test_run(self, document_store):
|
||||
writer = DocumentWriter(document_store)
|
||||
documents = [
|
||||
Document(content="This is the text of a document."),
|
||||
@ -80,8 +92,7 @@ class TestDocumentWriter:
|
||||
result = writer.run(documents=documents)
|
||||
assert result["documents_written"] == 2
|
||||
|
||||
def test_run_skip_policy(self):
|
||||
document_store = InMemoryDocumentStore()
|
||||
def test_run_skip_policy(self, document_store):
|
||||
writer = DocumentWriter(document_store, policy=DuplicatePolicy.SKIP)
|
||||
documents = [
|
||||
Document(content="This is the text of a document."),
|
||||
@ -108,8 +119,7 @@ class TestDocumentWriter:
|
||||
await writer.run_async(documents=documents)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_async(self):
|
||||
document_store = InMemoryDocumentStore()
|
||||
async def test_run_async(self, document_store):
|
||||
writer = DocumentWriter(document_store)
|
||||
documents = [
|
||||
Document(content="This is the text of a document."),
|
||||
@ -120,8 +130,7 @@ class TestDocumentWriter:
|
||||
assert result["documents_written"] == 2
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_async_skip_policy(self):
|
||||
document_store = InMemoryDocumentStore()
|
||||
async def test_run_async_skip_policy(self, document_store):
|
||||
writer = DocumentWriter(document_store, policy=DuplicatePolicy.SKIP)
|
||||
documents = [
|
||||
Document(content="This is the text of a document."),
|
||||
|
Loading…
x
Reference in New Issue
Block a user