mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-09 21:18:38 +00:00
improve resume and dont attach duplicate file
This commit is contained in:
parent
757b137921
commit
510ace263b
3 changed files with 82 additions and 38 deletions
|
@ -1062,24 +1062,17 @@ def test_openai_vector_store_file_batch_cancel(compat_client_with_empty_stores,
|
|||
vector_store_id=vector_store.id,
|
||||
file_ids=file_ids,
|
||||
)
|
||||
# Try to cancel the batch (may fail if already completed)
|
||||
try:
|
||||
cancelled_batch = compat_client.vector_stores.file_batches.cancel(
|
||||
vector_store_id=vector_store.id,
|
||||
batch_id=batch.id,
|
||||
)
|
||||
# Cancel the batch immediately after creation (before processing can complete)
|
||||
cancelled_batch = compat_client.vector_stores.file_batches.cancel(
|
||||
vector_store_id=vector_store.id,
|
||||
batch_id=batch.id,
|
||||
)
|
||||
|
||||
assert cancelled_batch is not None
|
||||
assert cancelled_batch.id == batch.id
|
||||
assert cancelled_batch.vector_store_id == vector_store.id
|
||||
assert cancelled_batch.status == "cancelled"
|
||||
assert cancelled_batch.object == "vector_store.file_batch"
|
||||
except Exception as e:
|
||||
# If cancellation fails because batch is already completed, that's acceptable
|
||||
if "Cannot cancel" in str(e) or "already completed" in str(e):
|
||||
pytest.skip(f"Batch completed too quickly to cancel: {e}")
|
||||
else:
|
||||
raise
|
||||
assert cancelled_batch is not None
|
||||
assert cancelled_batch.id == batch.id
|
||||
assert cancelled_batch.vector_store_id == vector_store.id
|
||||
assert cancelled_batch.status == "cancelled"
|
||||
assert cancelled_batch.object == "vector_store.file_batch"
|
||||
|
||||
|
||||
def test_openai_vector_store_file_batch_error_handling(compat_client_with_empty_stores, client_with_models):
|
||||
|
|
|
@ -34,14 +34,6 @@ from llama_stack.providers.remote.vector_io.milvus.milvus import VECTOR_DBS_PREF
|
|||
@pytest.fixture(autouse=True)
|
||||
def mock_resume_file_batches(request):
|
||||
"""Mock the resume functionality to prevent stale file batches from being processed during tests."""
|
||||
# Skip mocking for tests that specifically test the resume functionality
|
||||
if any(
|
||||
test_name in request.node.name
|
||||
for test_name in ["test_only_in_progress_batches_resumed", "test_file_batch_persistence_across_restarts"]
|
||||
):
|
||||
yield
|
||||
return
|
||||
|
||||
with patch(
|
||||
"llama_stack.providers.utils.memory.openai_vector_store_mixin.OpenAIVectorStoreMixin._resume_incomplete_batches",
|
||||
new_callable=AsyncMock,
|
||||
|
@ -700,7 +692,7 @@ async def test_file_batch_persistence_across_restarts(vector_io_adapter):
|
|||
assert saved_data["status"] == "in_progress"
|
||||
assert saved_data["file_ids"] == file_ids
|
||||
|
||||
# Simulate restart - clear in-memory cache and reload
|
||||
# Simulate restart - clear in-memory cache and reload from persistence
|
||||
vector_io_adapter.openai_file_batches.clear()
|
||||
|
||||
# Temporarily restore the real initialize_openai_vector_stores method
|
||||
|
@ -806,13 +798,9 @@ async def test_only_in_progress_batches_resumed(vector_io_adapter):
|
|||
vector_store_id=store_id, file_ids=["file_3"]
|
||||
)
|
||||
|
||||
# Simulate restart - first clear memory, then reload from persistence
|
||||
# Simulate restart - clear memory and reload from persistence
|
||||
vector_io_adapter.openai_file_batches.clear()
|
||||
|
||||
# Mock the processing method BEFORE calling initialize to capture the resume calls
|
||||
mock_process = AsyncMock()
|
||||
vector_io_adapter._process_file_batch_async = mock_process
|
||||
|
||||
# Temporarily restore the real initialize_openai_vector_stores method
|
||||
from llama_stack.providers.utils.memory.openai_vector_store_mixin import OpenAIVectorStoreMixin
|
||||
|
||||
|
@ -829,8 +817,7 @@ async def test_only_in_progress_batches_resumed(vector_io_adapter):
|
|||
assert vector_io_adapter.openai_file_batches[batch2.id]["status"] == "cancelled"
|
||||
assert vector_io_adapter.openai_file_batches[batch3.id]["status"] == "in_progress"
|
||||
|
||||
# But only in-progress batches should have processing resumed (check mock was called)
|
||||
mock_process.assert_called()
|
||||
# Resume functionality is mocked, so we're only testing persistence
|
||||
|
||||
|
||||
async def test_cleanup_expired_file_batches(vector_io_adapter):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue