mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 09:53:45 +00:00
fix(tests): add OpenAI client connection cleanup to prevent CI hangs (#4119)
# What does this PR do? Add explicit connection cleanup and shorter timeouts to OpenAI client fixtures. Fixes CI deadlock after 25+ tests due to connection pool exhaustion. Also adds 60s timeout to test_conversation_context_loading as safety net. ## Test Plan tests pass Signed-off-by: Charlie Doern <cdoern@redhat.com>
This commit is contained in:
parent
63137f9af1
commit
37853ca558
3 changed files with 23 additions and 3 deletions
|
|
@ -323,7 +323,13 @@ def require_server(llama_stack_client):
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def openai_client(llama_stack_client, require_server):
|
def openai_client(llama_stack_client, require_server):
|
||||||
base_url = f"{llama_stack_client.base_url}/v1"
|
base_url = f"{llama_stack_client.base_url}/v1"
|
||||||
return OpenAI(base_url=base_url, api_key="fake")
|
client = OpenAI(base_url=base_url, api_key="fake", max_retries=0, timeout=30.0)
|
||||||
|
yield client
|
||||||
|
# Cleanup: close HTTP connections
|
||||||
|
try:
|
||||||
|
client.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=["openai_client", "client_with_models"])
|
@pytest.fixture(params=["openai_client", "client_with_models"])
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,15 @@ def openai_client(base_url, api_key, provider):
|
||||||
client = LlamaStackAsLibraryClient(config, skip_logger_removal=True)
|
client = LlamaStackAsLibraryClient(config, skip_logger_removal=True)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
return OpenAI(
|
client = OpenAI(
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
api_key=api_key,
|
api_key=api_key,
|
||||||
|
max_retries=0,
|
||||||
|
timeout=30.0,
|
||||||
)
|
)
|
||||||
|
yield client
|
||||||
|
# Cleanup: close HTTP connections
|
||||||
|
try:
|
||||||
|
client.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,14 @@ class TestConversationResponses:
|
||||||
conversation_items = openai_client.conversations.items.list(conversation.id)
|
conversation_items = openai_client.conversations.items.list(conversation.id)
|
||||||
assert len(conversation_items.data) >= 4 # 2 user + 2 assistant messages
|
assert len(conversation_items.data) >= 4 # 2 user + 2 assistant messages
|
||||||
|
|
||||||
|
@pytest.mark.timeout(60, method="thread")
|
||||||
def test_conversation_context_loading(self, openai_client, text_model_id):
|
def test_conversation_context_loading(self, openai_client, text_model_id):
|
||||||
"""Test that conversation context is properly loaded for responses."""
|
"""Test that conversation context is properly loaded for responses.
|
||||||
|
|
||||||
|
Note: 60s timeout added due to CI-specific deadlock in pytest/OpenAI client/httpx
|
||||||
|
after running 25+ tests. Hangs before first HTTP request is made. Works fine locally.
|
||||||
|
Investigation needed: connection pool exhaustion or event loop state issue.
|
||||||
|
"""
|
||||||
conversation = openai_client.conversations.create(
|
conversation = openai_client.conversations.create(
|
||||||
items=[
|
items=[
|
||||||
{"type": "message", "role": "user", "content": "My name is Alice. I like to eat apples."},
|
{"type": "message", "role": "user", "content": "My name is Alice. I like to eat apples."},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue