Skip to content

Commit 37853ca

Browse files
authored
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 <[email protected]>
1 parent 63137f9 commit 37853ca

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

tests/integration/fixtures/common.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,13 @@ def require_server(llama_stack_client):
323323
@pytest.fixture(scope="session")
324324
def openai_client(llama_stack_client, require_server):
325325
base_url = f"{llama_stack_client.base_url}/v1"
326-
return OpenAI(base_url=base_url, api_key="fake")
326+
client = OpenAI(base_url=base_url, api_key="fake", max_retries=0, timeout=30.0)
327+
yield client
328+
# Cleanup: close HTTP connections
329+
try:
330+
client.close()
331+
except Exception:
332+
pass
327333

328334

329335
@pytest.fixture(params=["openai_client", "client_with_models"])

tests/integration/responses/fixtures/fixtures.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,15 @@ def openai_client(base_url, api_key, provider):
115115
client = LlamaStackAsLibraryClient(config, skip_logger_removal=True)
116116
return client
117117

118-
return OpenAI(
118+
client = OpenAI(
119119
base_url=base_url,
120120
api_key=api_key,
121+
max_retries=0,
122+
timeout=30.0,
121123
)
124+
yield client
125+
# Cleanup: close HTTP connections
126+
try:
127+
client.close()
128+
except Exception:
129+
pass

tests/integration/responses/test_conversation_responses.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,14 @@ def test_conversation_multi_turn_and_streaming(self, openai_client, text_model_i
6565
conversation_items = openai_client.conversations.items.list(conversation.id)
6666
assert len(conversation_items.data) >= 4 # 2 user + 2 assistant messages
6767

68+
@pytest.mark.timeout(60, method="thread")
6869
def test_conversation_context_loading(self, openai_client, text_model_id):
69-
"""Test that conversation context is properly loaded for responses."""
70+
"""Test that conversation context is properly loaded for responses.
71+
72+
Note: 60s timeout added due to CI-specific deadlock in pytest/OpenAI client/httpx
73+
after running 25+ tests. Hangs before first HTTP request is made. Works fine locally.
74+
Investigation needed: connection pool exhaustion or event loop state issue.
75+
"""
7076
conversation = openai_client.conversations.create(
7177
items=[
7278
{"type": "message", "role": "user", "content": "My name is Alice. I like to eat apples."},

0 commit comments

Comments
 (0)