Commit Graph
13 Commits
Author SHA1 Message Date
Alexsander HamirandGitHub 9a0658084b Fix SSL test failures due to caching and test isolation issues (#16973)
This commit fixes two critical test failures and two test isolation issues
in the SSL configuration tests.

## Critical Test Failures Fixed

### 1. test_get_ssl_configuration
**Problem:** Test was failing with assertion error that ssl.create_default_context
was never called (expected 1 call, got 0).

**Root Cause:** The get_ssl_configuration() function uses a caching mechanism
(_ssl_context_cache) to avoid creating duplicate SSL contexts with the same
configuration. When tests run in sequence, a previous test may have created an
SSL context with the same configuration (same cafile, ssl_security_level,
ssl_ecdh_curve). When this test runs, it retrieves the cached context instead
of creating a new one, so ssl.create_default_context() is never called, causing
the mock assertion to fail.

**Fix:** Clear the SSL context cache at the start of the test to ensure a fresh
context is created, allowing the mock to be called and verified.

### 2. test_ssl_ecdh_curve
**Problem:** Test was failing with assertion error that set_ecdh_curve was
never called (expected 1 call, got 0).

**Root Cause:** Same caching issue as above. Additionally, the test needed to
use a real SSLContext instance instead of a MagicMock because _create_ssl_context
calls methods like set_ciphers() and minimum_version that require a real context.

**Fix:**
- Clear the SSL context cache at the start of the test
- Use a real SSLContext instance and patch set_ecdh_curve on it specifically
- Added explanatory comment about why a real context is needed

## Test Isolation Issues Fixed

### 3. test_ssl_security_level
**Problem:** Test was failing because it expected LiteLLMAiohttpTransport but
got httpx.AsyncHTTPTransport instead.

**Root Cause:** Test isolation issue. Other tests in the file (test_force_ipv4_transport,
test_aiohttp_disabled_transport) set litellm.disable_aiohttp_transport = True
but don't restore the original value. When this test runs after those tests,
aiohttp transport is disabled, causing it to use httpx transport instead.

**Fix:** Explicitly enable aiohttp transport at the start of the test and restore
the original value in a finally block, ensuring the test works regardless of
test execution order.

### 4. test_ssl_verification_with_aiohttp_transport
**Problem:** Same as above - expected LiteLLMAiohttpTransport but got
httpx.AsyncHTTPTransport.

**Root Cause:** Same test isolation issue - aiohttp transport disabled by
previous tests.

**Fix:** Same approach - explicitly enable aiohttp transport and restore
original value in finally block.

## Why These Fixes Work

1. **Cache clearing:** By clearing _ssl_context_cache before each test, we
   ensure that get_ssl_configuration() creates a fresh SSL context, allowing
   mocks to be properly called and verified.

2. **Test isolation:** By saving and restoring the disable_aiohttp_transport
   setting, tests are independent of each other and work correctly regardless
   of execution order.

These are minimal, targeted fixes that address the root causes without
modifying production code or affecting other functionality.
2025-11-22 10:07:30 -08:00
AlexsanderHamir d094a334d9 add: unit test 2025-10-14 16:38:04 -07:00
Dharamendra Kumar 04acd4b739 Update var name for consistency 2025-09-23 10:28:40 -07:00
Dharamendra Kumar 77a39e7ca9 feat: Add shared_session parameter for aiohttp ClientSession reuse
Allow passing aiohttp.ClientSession to acompletion() calls for better
performance and resource management. Includes debug logging, tests,
and documentation. Backward compatible.
2025-09-19 01:46:53 -07:00
Joost van DoornandGitHub 453591ed7c Fix: Fix custom ca bundle support in aiohttp transport (#12281)
* Unify usage of get_ssl_configuration

* Fix doc
2025-07-04 12:48:20 -07:00
Ishaan JaffandGitHub 22ff3da3cf [Fix] Allow using HTTP_ Proxy settings with trust_env (#12066)
* allow using trust_env

* add docs on how to use HTTP_PROXY

* docs AIOHTTP_TRUST_ENV

* test_aiohttp_transport_trust_env_setting

* docs fix
2025-06-26 08:37:22 -07:00
Ishaan JaffandGitHub d4b34549bc [Fix] Networking - allow using CA Bundles (#11906)
* fix _get_ssl_context

* fixes for using HTTP handler
2025-06-19 20:09:08 -07:00
Ishaan Jaff 098fb0307a Revert "Enable System Proxy Support for aiohttp Transport (#11616)"
This reverts commit 33c134c6ac.
2025-06-14 08:32:51 -07:00
DelandGitHub 33c134c6ac Enable System Proxy Support for aiohttp Transport (#11616)
* feat: enable proxy for aiohttp, fixes 11389

* chore: add test for aiohttp trust env

* style: format litellm/__init__.py
2025-06-11 21:13:37 -07:00
Ishaan Jaff 6863073aa4 fix: tests 2025-05-31 13:14:37 -07:00
Ishaan Jaff 7d47417906 test: fixes 2025-05-31 12:42:56 -07:00
Ishaan JaffandGitHub 4d2edc4e7a [Fixes] Aiohttp transport fixes - add handling for aiohttp.ClientPayloadError and ssl_verification settings (#11162)
* fix: AiohttpResponseStream transport

* fix: use AiohttpResponseStream transport by default

* fix: AiohttpResponseStream transport

* fixes: mapping aiohttp exceptions

* fixes: aiohttp rollout

* fixes: add support ssl_verify for aiohttp

* fixes: add support ssl_verify for aiohttp

* fixes: remove duplicates
2025-05-26 21:14:35 -07:00
Krish DholakiaandGitHub ef42461c1e Litellm fix GitHub action testing (#11163)
* test: add __init__.py files

* refactor: rename test folder to avoid naming conflict

* test: update workflows

* test: update tests

* test: update imports

* test: update tests

* test: remove unused import

* ci(test-litellm.yml): add pytest retry to github workflow

* test: fix test
2025-05-26 14:41:42 -07:00