litellm/tests/router_unit_tests
Alexsander Hamir ddb90c9ad7
[Fix] - Router: add model_name index for O(1) deployment lookups (#15113)
* perf(router): add model_name index for O(1) deployment lookups

Add model_name_to_deployment_indices mapping to optimize _get_all_deployments()
from O(n) to O(1) + O(k) lookups.

- Add model_name_to_deployment_indices: Dict[str, List[int]]
- Add _build_model_name_index() to build/maintain the index
- Update _add_model_to_list_and_index_map() to maintain both indices
- Refactor to use idx = len(self.model_list) before append (cleaner)
- Optimize _get_all_deployments() to use index instead of linear scan

* test(router): add test coverage for _build_model_name_index

Add single comprehensive test for _build_model_name_index() function to fix
code coverage CI failure.

The test verifies:
- Index correctly maps model_name to deployment indices
- Handles multiple deployments per model_name
- Clears and rebuilds index correctly

Fixes: CI code coverage error for _build_model_name_index
2025-10-06 08:14:11 -07:00
..
conftest.py [Perf] Improvements for Async Success Handler (Logging Callbacks) - Approx +130 RPS (#13905) 2025-08-23 13:13:23 -07:00
create_mock_standard_logging_payload.py (refactor) - migrate router.deployment_callback_on_success to use StandardLoggingPayload (#7015) 2024-12-03 20:29:25 -08:00
gettysburg.wav test(router_code_coverage.py): check if all router functions are dire… (#6186) 2024-10-14 22:44:00 -07:00
README.md test(router_code_coverage.py): check if all router functions are dire… (#6186) 2024-10-14 22:44:00 -07:00
test_router_adding_deployments.py Support env var vertex credentials for passthrough + ignore space id on watsonx deployment (throws Json validation errors) (#11527) 2025-06-07 20:31:05 -07:00
test_router_batch_utils.py fix(vertexai-batch): fix vertexai batch file format (#13576) 2025-08-18 10:19:23 -07:00
test_router_cooldown_utils.py [Prometheus] Move Prometheus to enterprise folder (#12659) 2025-07-18 11:54:47 -07:00
test_router_endpoints.py [Perf] Improvements for Async Success Handler (Logging Callbacks) - Approx +130 RPS (#13905) 2025-08-23 13:13:23 -07:00
test_router_handle_error.py fix(handle_error.py): add unit tests 2025-08-11 18:25:30 -07:00
test_router_helper_utils.py [Bug Fix] x-litellm-tags not routing with Responses API (#14289) 2025-09-05 09:40:37 -07:00
test_router_index_management.py [Fix] - Router: add model_name index for O(1) deployment lookups (#15113) 2025-10-06 08:14:11 -07:00
test_router_prompt_caching.py Litellm dev 12 07 2024 (#7086) 2024-12-08 00:30:33 -08:00

Router component unit tests.

Please name all files with the word 'router' in them.

This is used to ensure all functions in the router are tested.