fix(tests): isolate mock session payloads in Vertex AI session service tests - #7158
Open
Jinzhengxu wants to merge 1 commit into
Open
Jinzhengxu wants to merge 1 commit into
Jinzhengxu wants to merge 1 commit into
Conversation
…e tests The mock_api_client_instance fixture registered the module-level MOCK_SESSION_JSON_* dicts directly in session_dict, while MockAsyncClient rewrites session_dict[id]['update_time'] whenever an event is appended. Any test that appends an event to session '1' therefore mutated the shared dict, and later tests comparing get_session() against MOCK_SESSION (built at import time from the original timestamp) failed depending on execution order. Deep-copy the session payloads in the fixture, matching how the fixture already copies the event payloads.
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
tests/unittests/sessions/test_vertex_ai_session_service.pyis order-dependent.The
mock_api_client_instancefixture registers the module-levelMOCK_SESSION_JSON_1/2/3/PAGE1/PAGE2dicts directly insession_dict, whileMockAsyncClient._append_eventrewritessession_dict[id]['update_time']inplace. Every
test_append_event*test therefore mutates the sharedMOCK_SESSION_JSON_1(itsupdate_timebecomes the appended event'stimestamp), and any later test that compares
get_session()againstMOCK_SESSION(built once at import time from the original timestamp) fails:In the default file order the append tests happen to run after the comparisons,
so this is invisible in CI today, but it surfaces as soon as the order changes:
with
pytest-randomly, the file alone fails under every seed tried (1–6, 1–2failures each), and
pytest tests/unittests -n 8failstest_get_and_delete_sessionandtest_delete_session_rejects_other_users_sessionunder seeds 1 and 2. Running each of the nine
test_append_event*testsimmediately before
test_get_and_delete_sessionreproduces the failuredeterministically in a single process.
Solution:
Deep-copy the session payloads in the fixture, exactly as the fixture already
does for the event payloads (
copy.deepcopy(MOCK_EVENT_JSON)), so each testgets its own
session_dictentries and in-place updates cannot leak acrosstests. No production code is touched.
Testing Plan
Unit Tests:
Test-only change; the fixture itself is the fix. Results on this branch:
pytest tests/unittests/sessions/test_vertex_ai_session_service.py: 54 passedin default order and under
pytest-randomlyseeds 1–6 (previously 1–2failures per seed).
pytest tests/unittests -n 8withpytest-randomlyseeds 1 and 2: 2 of 2 runs green (15099 passed, 84 skipped, 27 xfailed, 2 xpassed each)(on
mainboth seeds failed the two tests above).pyink --checkandisort --check-onlyon the file: unchanged.Manual End-to-End (E2E) Tests:
Not applicable (test-only change).
Checklist
Additional context
Found while running the unit suite under random ordering. The nine polluting
tests are
test_append_event,test_append_event_with_compaction,test_append_event_with_compaction_and_custom_metadata,test_append_event_with_usage_metadata,test_append_event_with_usage_metadata_and_compaction,test_append_event_with_part_metadata_round_trips,test_append_event_strips_unsupported_part_metadata,test_append_event_retries_once_on_429andtest_append_event_fallback_for_older_sdk; each appends an event to session'1'.