Repository navigation
Report setup and intermediate command failures through the assertion - #728
Conversation
eerxuan
left a comment
There was a problem hiding this comment.
Summary
Routing setup and intermediate failures to the test's single assertion is the right fix, and every test still makes exactly one assertion. getParameter, getCmdLineOpts and the listIndexes loops pass the failed result on as is, which is the clearest pattern. One change can now let a test pass when it shouldn't, and one test still crashes before its assertion.
Critical Issues
- [Required]
test_setQuerySettings_verification.py,test_setQuerySettings_hash_different:setup_hashstaysNonewhen a setup command fails or its reply has noqueryShapeHash.result["queryShapeHash"] != Noneis thenTrue, so the test passes without ever comparing two hashes. Before this change it raisedTypeError. Please pass a failed setup result to the assertion (astest_setQuerySettings_remove/_updatenow do), and treat a missing setup hash as a failure rather than as "differ".result["queryShapeHash"]still raisesKeyErrorwhen the command reply has no hash. - [Required]
test_serverStatus_core_behavior.py,test_serverStatus_cross_database_same_core_fields:admin_result.get(...)isn't guarded, so a failed adminserverStatusstill raisesAttributeErroroutside the helper.
Suggestions
-
[Suggestion] When the first (reference) call fails, these tests compare the second result against
None. So the failure readsexpected 'pid' == Noneand the first call's real error is lost:test_serverStatus_pid_consistent_across_calls(result1)test_hello_connectionId_stable(r1)test_hello_legacy_isMaster_fields_match(r_hello)test_hello_response_topologyVersion_processId_stable(r1)test_dbStats_scale_divides_data_size(unscaled/scaled, reported asFalse != True)
Passing the failed result to the assertion, as the
getParameterandgetCmdLineOptschanges in this PR do, would report the real error. -
[Suggestion]
test_changeStream_resume.py:_first_event_token_or_errorand_event_token_of_type_or_errorduplicate_first_event_token/_event_token_of_type, which still have other callers. Folding the error return into the originals keeps one helper per job, the same approach as #734 withopen_find_cursors. Separately,_first_event_token_or_errorstill raisesIndexErroron an empty batch, and_event_token_of_type_or_errorreturnsNonewhen no matching event arrives. ThatNoneis then sent asstartAfter: null, so the failure is about the argument rather than the missing event. -
[Suggestion]
test_changeStream_events.py,_emit_event: the plainassert matchingthat follows the new checks still fails outside the helper when the expected event isn't in the batch. Returning the getMore result in that case would let the test's assertion report it.
Questions
- [Nitpick] The branch is 3 commits behind main. Please rebase before merge.
Positive Feedback
- The
listIndexesgetMore loops stop at the first failed getMore and pass that error on, instead of looping on an exception. test_setQuerySettings_remove/_updatepass the first failed setup result on, rather than building the command from it.
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage); P0 keyword "crash" in body; effort from diff stats (298+135 LOC, 15 files); LLM: Improves test robustness by surfacing real engine errors through assertions instead of crashing with TypeError/KeyError/AttributeError, touching multiple test files across one framework component. If a label is wrong, remove it manually and ping |
Several compatibility tests crash with a Python TypeError/AttributeError/ KeyError before reaching framework/assertions.py when a setup or intermediate execute_command result is an engine exception (or a successful response missing a field): they index into the exception, iterate it, or build an expectation from a missing field. Apply the PR documentdb#718 pattern across these tests: extract cursor ids and response fields defensively, and forward a failed setup/intermediate result to the test's single assertion so the engine's real error or value is visible through a framework assertion helper instead of a raw crash. Where a first response is missing a field, read it with .get(...) so the assertion reports the mismatch. MongoDB behavior and the checked property are unchanged. Covers listIndexes cursor batching, bulkWrite getMore drain, changeStream events/event-read-error/resume, setQuerySettings response/remove/update and hash tests, getParameter *, allParameters+named and setAt variants, dbStats scale/avgObjSize, getCmdLineOpts, serverStatus, and hello. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
test_setQuerySettings_hash_same and test_setQuerySettings_hash_different now forward a failed setup command to the assertion, as the remove and update tests do. hash_different treats a missing hash on either the setup reply or the command reply as a failure instead of a difference, and reads the command hash with .get() so a reply without one no longer raises KeyError. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
The serverStatus, hello and dbStats consistency tests compare a second reply against fields read from a first reference reply. When the reference call fails, its error is now passed to the assertion instead of comparing the second reply against None. The serverStatus host and version checks and the cross-database check no longer index a failed reply outside the helper. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Fold the error return into _first_event_token and _event_token_of_type and drop the _or_error copies. The helpers return the engine error, or a LookupError when the batch is empty or has no event of the requested type, and every caller forwards it to the test's assertion instead of indexing into it or sending startAfter: null. _emit_event returns the getMore reply when the batch has no event of the expected type, so the test's assertion reports what the stream delivered instead of a bare assert failing outside the helper. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
de76c37 to
bf097fe
Compare
|
Thanks @eerxuan, all addressed:
On MongoDB 8.2.4 the 15 touched files pass 249/249, same as main. A stubbed executor confirms every failure path now fails through the assertion helper. |
|
Several tests run a setup or intermediate command (open a cursor or change stream, capture a resume token, run a reference call) and then index into its reply before reaching the assertion. When that command fails on the engine under test, the test crashed with a raw
TypeError,KeyError,IndexError,AttributeErrororStopIterationoutside the assertion helper. The real engine error never reached the report. In a few cases the test passed without comparing anything.This PR forwards the failed result to the test's single assertion, so the failure is reported by
framework/assertions.pywith the engine's own error. MongoDB behaviour and the property each test checks are unchanged, and each test still makes exactly one assertion.Changes
listIndexesreply and everygetMore; forward the first failure._emit_eventreturns the open orgetMoreerror, and returns thegetMorereply when the batch has no event of the expected type, so the test'sassertPropertiesreports what the stream delivered._first_event_tokenand_event_token_of_typereturn the engine error, or aLookupErrorwhen the capture batch is empty or has no event of the requested type. Every caller forwards it to the assertion instead of indexing into it or sendingstartAfter: null. Callers that open a resumed stream and thengetMorealso forward a failed open.bulkWriteinstead of reading its cursor id.response_contains_hash/response_contains_representative_queryno longer read fields off an exception.remove,update,hash_sameandhash_differentforward a failed setup command to the assertion.hash_differenttreats a missing hash on either the setup reply or the command reply as a failure, not a difference, and reads the command hash with.get().hash_formatforwards a failed command.pid,hostandversionconsistency checks and the cross-database check forward a failed reference call instead of comparing againstNoneor indexing it.connectionId_stable,legacy_isMaster_fields_matchandtopologyVersion_processId_stableforward a failed reference call.scale_divides_data_sizeforwards a faileddbStatscall;avgObjSizeno longer divides fields read off a failed or incomplete reply.Testing
black,isort,flake8,mypy(pre-commit) pass;pytest -m unitpasses (152).main.maineach case raisedTypeError,KeyError,IndexError,AttributeErrororStopIterationoutside the helper, andhash_differentpassed when the setup reply had no hash. On this branch every case fails through the assertion helper ([UNEXPECTED_ERROR],[ERROR_MISMATCH],[RESULT_MISMATCH]or[PROPERTY_MISMATCH]), and the happy path still passes.