test(tracing): mock urlopen as a context manager in flush_pending test - #55
Merged
Merged
Conversation
Signed-off-by: Jeriah Keith <jeriahkeithit@gmail.com>
Collaborator
|
Hi @Yeriahz thanks for catching this! LGTM, merging! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a broken mock in
test_pending_threads_self_evict_when_post_returns. Test-only change; no production code touched.Problem
The test patches
urlopenwithside_effect=fast_post, wherefast_postreturnsNone. The production code atsrc/nooa/tracing/_litellm_journal.py:218uses the result as a context manager:with None:raisesTypeError: 'NoneType' object does not support the context manager protocol, so every POST fails, retries three times, and takes ~4s. The test waits at most 5s for_PENDING_THREADSto drain, which makes it flaky on slower machines.More importantly, the test never exercises what its name and docstring describe. The POST never returns; it errors and gives up, so the eviction being verified happens on the failure path rather than the success path. That holds regardless of hardware.
Fix
Return a
MagicMockwith__enter__/__exit__defined, matching the existing_ok_response()helper intests/tracing/test_http_exporter_drops.py:51.Related issues
None.
Validation
Before: fails 4 of 5 runs, ~5s each. After: passes 5 of 5, ~0.07s each.
Two unrelated timing tests fail intermittently in my environment (a 4-vCPU VM); the set differs run to run and includes tests in modules this change doesn't touch.
Checklist
uv run ruff check .anduv run ruff format --check .pass)uv run pytest)