enhancing python SDK test coverage#47360
Conversation
…aning up comments
|
@sdkReviewAgent-2 |
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR substantially expands azure-cosmos SDK coverage across sync + async surfaces, focusing on regressions and behavioral contracts around request headers (User-Agent, SessionToken, Content-Length, response headers), query/feed-range behavior, and routing-map provider resiliency. It also includes some docstring/comment cleanups.
Changes:
- Adds new regression/integration tests for
user_agent_overwrite,read_timeoutpropagation, session-token scoping for feed-range/partition-key queries, and UTF-8 decode fallback behavior (including paged iteration). - Extends routing-map provider unit + integration coverage (including 503 + sub-status assertions and concurrency scenarios).
- Adds additional query/feed-range and encoding (emoji) round-trip tests, plus async parity tests for aggregate utilities and response-header contracts.
Reviewed changes
Copilot reviewed 37 out of 37 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/cosmos/azure-cosmos/tests/test_user_agent_overwrite_regression.py | New sync regression tests for user_agent_overwrite combinations and wire User-Agent prefix capture. |
| sdk/cosmos/azure-cosmos/tests/test_user_agent_overwrite_regression_async.py | Async counterpart of the user_agent_overwrite regression suite. |
| sdk/cosmos/azure-cosmos/tests/test_session.py | Adds stronger feed-range session-token scoping tests (value/pagination/partition_key-only). |
| sdk/cosmos/azure-cosmos/tests/test_session_async.py | Async versions of the stronger feed-range session-token scoping tests. |
| sdk/cosmos/azure-cosmos/tests/test_session_token_unit.py | Adds direct unit coverage for set_session_token_header sync/async behavior for single-partition selection. |
| sdk/cosmos/azure-cosmos/tests/test_routing_map_provider_unit.py | Enhances unit coverage and asserts 503 sub-status for routing-map snapshot inconsistency; adds SmartRoutingMapProvider e2e tests. |
| sdk/cosmos/azure-cosmos/tests/test_routing_map_provider_unit_async.py | Async equivalent of routing-map provider unit enhancements and e2e tests. |
| sdk/cosmos/azure-cosmos/tests/routing/test_routing_map_provider.py | Adds SmartRoutingMapProvider end-to-end 503 conversion coverage in the routing integration suite. |
| sdk/cosmos/azure-cosmos/tests/routing/test_routing_map_provider_async.py | Refactors imports and adds SmartRoutingMapProvider async end-to-end tests; includes text updates in docstrings/comments. |
| sdk/cosmos/azure-cosmos/tests/test_response_decoding.py | Tightens/extends tests around env-var parsing and decode behavior; documentation updates. |
| sdk/cosmos/azure-cosmos/tests/test_response_decoding_paged.py | New tests for strict vs REPLACE/IGNORE decoding behavior across multiple sequential pages (sync + async request paths). |
| sdk/cosmos/azure-cosmos/tests/test_request_response_decoding.py | Simplifies docs and keeps wiring/behavior tests ensuring _Request uses shared decode helper and surfaces typed exceptions. |
| sdk/cosmos/azure-cosmos/tests/test_read_timeout_propagation.py | New sync tests to verify read_timeout propagation to transport kwargs across query entry points and precedence rules. |
| sdk/cosmos/azure-cosmos/tests/test_read_timeout_propagation_async.py | Async parity for read-timeout propagation assertions. |
| sdk/cosmos/azure-cosmos/tests/test_query_response_headers_async.py | Adds additional async response-header contract tests and a long-pagination bounded-memory test. |
| sdk/cosmos/azure-cosmos/tests/test_query_feed_range.py | Adds multi-partition SELECT VALUE shape/merge assertions for non-aggregate vs aggregate projections. |
| sdk/cosmos/azure-cosmos/tests/test_query_feed_range_async.py | Async parity for the multi-partition SELECT VALUE shape/merge assertions. |
| sdk/cosmos/azure-cosmos/tests/test_query_feed_range_multipartition_async.py | Adjusts async client creation to exercise AAD lane; adds pagination resume tests and safety-guard tests for stalled/overlap cases. |
| sdk/cosmos/azure-cosmos/tests/test_query_aggregate_utils_unit_async.py | New async-side unit tests ensuring shared aggregate classifier/merge behavior parity. |
| sdk/cosmos/azure-cosmos/tests/test_partition_split_retry_unit.py | Expands/cleans up unit tests around structured continuation tokens and removes noisy debug printing. |
| sdk/cosmos/azure-cosmos/tests/test_partition_split_retry_unit_async.py | Async parity for the continuation-token explode/resume and routing-lookup failure checkpoint behavior. |
| sdk/cosmos/azure-cosmos/tests/test_feed_range_continuation_token.py | Extends aggregate detection/merge tests (MIN/MAX case insensitivity, mixed numeric types, boolean classification guards). |
| sdk/cosmos/azure-cosmos/tests/test_encoding.py | Adds sync emoji/multibyte round-trip tests (point + query). |
| sdk/cosmos/azure-cosmos/tests/test_encoding_async.py | New async emoji/multibyte round-trip tests (point + query). |
| sdk/cosmos/azure-cosmos/tests/test_cosmos_paged_unit.py | New unit tests for sync paged wrappers (CosmosItemPaged, CosmosDict, CosmosList) response-header API semantics. |
| sdk/cosmos/azure-cosmos/tests/test_cosmos_paged_unit_async.py | New unit tests for async paged wrapper (CosmosAsyncItemPaged) and response-header API guards. |
| sdk/cosmos/azure-cosmos/tests/test_content_length_encoding.py | Simplifies docs and adds bytes/bytearray body behavior pinning in Content-Length tests (sync + async). |
| sdk/cosmos/azure-cosmos/tests/test_availability_strategy.py | Adds test ensuring per-request availability_strategy=None falls back to client-level hedging strategy (sync). |
| sdk/cosmos/azure-cosmos/tests/test_availability_strategy_async.py | Async parity for availability_strategy=None fallback behavior. |
| sdk/cosmos/azure-cosmos/tests/test_aio_extras_packaging_unit.py | New packaging metadata test ensuring aio extras are declared and async module imports. |
| sdk/cosmos/azure-cosmos/azure/cosmos/_location_cache.py | Docstring/comment tightening for location list cleaning and region-name normalization logic. |
|
✅ Review complete (56:08) Posted 6 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
|
@sdkReviewAgent-2 |
|
/azp run python - cosmos - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
✅ Review complete (59:21) Posted 8 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
|
@sdkReviewAgent-2 |
|
✅ Review complete (07:24) Posted 7 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
|
@sdkReviewAgent-2 |
|
|
||
| # Collect transient setup objects so they don't show up as growth. | ||
| gc.collect() | ||
| tracemalloc.start() |
There was a problem hiding this comment.
🟡 Recommendation — tracemalloc.stop() not guarded by finally
tracemalloc.start() at line 274 and tracemalloc.stop() at line 297 are both on the happy path. If any assertion inside the pagination loop (e.g., line 287: self.assertIsNotNone(headers)) or the query itself throws, stop() is never called and the tracer stays active for all subsequent tests in the session. This adds a small per-allocation overhead that can skew memory measurements in other tests and, in the worst case, cause cascading false positives in other tracemalloc-based tests.
The outer try/finally only cleans up the container — it does not stop tracing.
The same pattern appears in test_query_response_headers_async.py (lines 292/316).
Suggestion:
tracemalloc.start()
try:
snapshot_before = tracemalloc.take_snapshot()
# ... iteration + snapshots ...
memory_growth = sum(stat.size_diff for stat in top_stats if stat.size_diff > 0)
finally:
tracemalloc.stop()|
✅ Review complete (07:57) Posted 1 inline comment(s). Steps: ✓ context, correctness, cross-sdk, design, history, past-prs, synthesis, test-coverage |
enhancing python SDK test coverage