Repository navigation
Fix/compat test side fixes - #734
Conversation
killCursors/getMore tests opened a cursor with a raw command and indexed res["cursor"]["id"] directly. When the engine rejects the open the result is an exception, so the index raised a bare TypeError outside the assertion helper and the test could not take an override. Add open_find_cursors_or_error and forward a captured open failure into each test's single assertion so it fails through the helper with the engine's real result. MongoDB behavior and test intent unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
These tests opened a base $changeStream and read opened["cursor"]["postBatchResumeToken"] directly; when the open is rejected the result is an exception and the index raised a bare TypeError outside the helper. Forward a captured open failure into the single assertResult. MongoDB behavior and test intent unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
…on helper test_rand_in_object_expression indexed result["cursor"]["firstBatch"] on a raw result, and the collStats histogram test raised a bare AssertionError on an engine error. Route both through the assertion helper (guarded index / assertResult not_error) so they fail overridably with the real result. MongoDB behavior unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
geospatial and wildcard valid-data tests loaded docs with collection.insert_many (raises BulkWriteError); dbStats re-raised a setup failure; listIndexes enabled the profiler with a raw db.command; commitTransaction called session.commit_transaction after an op the engine rejects in a txn. Each raised outside the assertion helper. Load via execute_command / forward the captured setup/commit failure into the single assertion so each fails overridably with the engine's real result. MongoDB unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
…ommands Four section-4 "smoke tests no run can judge" issues not covered by documentdb#731: - logout: run on a dedicated client. logout de-authenticates the connection it runs on; on the shared pooled session connection it logs out every later test on the same xdist worker (authorization failure). - rolesInfo / usersInfo: query only the role/user the test creates, not the whole database. `{"rolesInfo": 1}` / `{"usersInfo": 1}` list every object, including ones parallel tests create and drop, so the result is non-deterministic. - fsync/autoCompact setup helpers (drain_fsync_lock, ensure_autocompact_idle): return instead of raising when the command is unsupported (COMMAND_NOT_FOUND 59 / FEATURE_NOT_SUPPORTED 303), so the test under test runs and judges the command instead of failing in setup. Each probe keeps the same assertion and is unchanged on an engine that supports the command. Verified on MongoDB 8.2.4. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Match the capability-probe pattern from documentdb#731 so these smoke tests stop failing on the cosmetic ok int32 vs double difference. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
execute_command and execute_admin_command return the raw command result, so a find with a small batchSize or an aggregate with $changeStream leaves a server cursor that no driver object owns. Nothing closes it when the test ends, and dropping the test database does not close it on every engine. The cursor stays open until the server's idle timeout. On an engine that caps open cursors per instance, those leftovers add up until a later test's find or aggregate is rejected with "Cannot open a new cursor since too many cursors are already opened". Which test hits the cap depends on timing and test order, so the failures look flaky and land on tests that did nothing wrong. Track the cursor id and namespace of every command result that returns an open cursor, and kill them with killCursors at teardown: in the collection and database_client fixtures before the drop, and in a new autouse fixture for tests that use neither. Cleanup is best effort and never changes a test's outcome. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
eerxuan
left a comment
There was a problem hiding this comment.
Summary
Three useful fixes, split into clean commits. MongoDB behavior is unchanged and CI is green. The cursor cleanup is careful: it is best effort, groups cursors per namespace, and has 7 unit cases. One place can still fail outside the assertion helper when an override provider is registered.
Critical Issues
- [Required]
test_collStats_output.py,test_collStats_output_histogram_structure: when an override provider registered through the assertion hook (#724) handles theassertResult(not_error=True)call, the call returns instead of raising. The next line,result["cursor"]["firstBatch"][0], then raisesTypeErroron the exception. Put the histogram checks in anelse:branch, orreturnafter the assertion.
Suggestions
- [Suggestion]
test_commitTransaction_supported_operations.py: 10 other tests in this file still callsession.commit_transaction()directly after an operation in the transaction. If that operation fails, the transaction is aborted and the commit raises outside the helper. Using_commit_or_errorin all of them would keep the file consistent. - [Suggestion] 28
open_find_cursors(...)call sites still index the open result and will crash the same way: 25 ingetMore/and 3 intest_killCursors_lifecycle.pyitself. Please convert them, or explain in the description why only these tests changed. Two helpers whose names differ only in whether they crash on an open error will confuse future authors. - [Suggestion]
test_smoke_rolesInfo/test_smoke_usersInfo: the old assertion wasassertSuccessPartial(result, {"ok": 1.0}), which compares onlyok, so the role or user list could never make it fail.assertCommandSupportedalone fixes the int32okcase.{"rolesInfo": 1}/{"usersInfo": 1}withassertCommandSupportedis enough, and the smoke probe then doesn't need to create a role, or a user with a password, inadmin. - [Suggestion]
test_geospatial_creation.py/test_wildcard_data_types.py: a rejected document comes back aswriteErrorsin anok: 1reply, so the assertion reports a find mismatch rather than the insert rejection. Forwarding the insert reply when it haswriteErrorswould surface the real error.
Questions
- [Nitpick]
test_listIndexes_comment_inherited_by_getMore:listed["cursor"]["id"]is still read without a check, so a failedlistIndexesraisesTypeErrorinside thetry. - [Nitpick] The description says
test_commitTransaction_supported_operationshadraise AssertionError(f"unexpected error: {result}"). That string is not in the file on main.
Positive Feedback
- Running
logouton a dedicated client follows the existingconnection_stringpattern (fsyncUnlock,abortTransaction). - The "unsupported means nothing to reset" early return in the fsync/autoCompact setup is narrow (codes 59 and 303 only), and behavior is unchanged where the commands are supported.
- The cursor tracking handles the admin
$cmd.aggregatenamespace and double kills (cursorsNotFound) without affecting test outcomes.
- collStats histogram: return after the error assertion, so an override
that handles the error doesn't fall through into the histogram checks.
- open_find_cursors and open_cursor return the open error instead of
indexing into it; open_find_cursors_or_error is folded into
open_find_cursors. Every caller in getMore/ and killCursors/ (and the
direct find/aggregate/listIndexes opens and intermediate getMore replies
in those files) passes a failed reply to the test's assertion.
- commitTransaction supported operations: every commit goes through
_commit_or_error, and the three driver writes through _apply_and_commit.
- rolesInfo/usersInfo smoke: back to {"rolesInfo": 1} / {"usersInfo": 1};
assertCommandSupported alone fixes the int32 ok case.
- geospatial/wildcard data load: a writeErrors entry in an ok: 1 insert
reply is forwarded as the WriteError the driver would raise for it.
- listIndexes comment-inherited-by-getMore: a failed listIndexes is
forwarded instead of indexed.
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage, test-framework); P0 keyword "crash" in body; effort from diff stats (1122+505 LOC, 33 files) If a label is wrong, remove it manually and ping |
Summary
This PR fixes three groups of tests that fail for reasons unrelated to the
command they test. In every case, the failure happens either in the test's own
setup or outside the framework assertion helper (
assertResult/assertSuccess/assertProperties). On MongoDB nothing changes; these testspass before and after. On an engine whose behavior differs from MongoDB, the
test now gets as far as its assertion and fails there with the engine's real
result. It can then be judged, or captured by the opt-in override hook (#724).
Before this change it crashed with an unrelated Python error, or failed because
of an earlier test.
The three groups touch separate files and are in separate commits, so they can
be reviewed one at a time:
1. Route helper-crash failures through the assertion helper
What was broken
These tests run a command or a setup step, then read or re-raise the raw result
before calling the assertion helper. When the engine returns an error instead
of the expected reply, the test crashes in that read, and the assertion never
runs:
getMore/andkillCursors/that opens a cursor, whether throughopen_find_cursors,open_cursor(tailable) or a directfind/aggregate/listIndexesres["cursor"]["id"]on a failed open raisedTypeError: 'OperationFailure' object is not subscriptable. Five tests also indexed a failed intermediategetMorereply the same waytest_changeStream_resume_mutual_exclusivity,test_changeStream_spec_acceptanceopened["cursor"]["postBatchResumeToken"]on a failed$changeStreamopen raised the sameTypeError$randprojectiontest_rand_in_object_expressionresult["cursor"]["firstBatch"]on a failed projection raised the sameTypeErrortest_collStats_output_histogram_structureraise AssertionError(f"unexpected error: {result}")raised the engine error outside the helpertest_geospatial_creation,test_wildcard_data_typescollection.insert_many(...)raisedBulkWriteErrorwhen the engine rejected a setup documenttest_dbStats_collection_scenariosraise setup_resultraised the setup error outside the helpertest_listIndexes_collection_variantsdb.command({"profile": 2})raised outside the helper, andlisted["cursor"]["id"]indexed a failedlistIndexestest_commitTransaction_supported_operationssession.commit_transaction()directly, and three ran a driver write (update_one,delete_one,insert_one) directly. When the operation failed, the write or the commit of the aborted transaction raised outside the helperWhat changed
Each test captures the result it already gets and passes it, or a
not_errorcheck, to the one assertion it already makes. No new assertions are added, so
the one-assertion-per-test rule still holds:
open_find_cursorsandopen_cursorincursor_test_case.pyreturn theopen error instead of indexing into it, and every caller passes that error to
its assertion. Tests that open a cursor with a direct command, or read an
intermediate
getMorereply, pass a failed reply on the same way.$randprojection index is guarded. The collStats histogram error goesthrough
assertResult(not_error=True).execute_commandinstead ofinsert_many. A rejected insert (an error, orwriteErrorsin anok: 1reply) is passed to the assertion in place of the find result, so the test
reports the insert rejection rather than a find mismatch.
listIndexesarepassed to the test's assertion.
_commit_or_error, and the three driverwrites through
_apply_and_commit, which return the engine error instead ofraising.
test_collStats_output_histogram_structure, the test returns after theerror assertion, so an override that handles the error doesn't fall through
into the histogram checks.
Not changed
test_sample_statistical_randomnessandtest_sample_statistical_uniformityare left as they are. They already fail inside their own statistical assertion,
because the engine's
$samplereally does behave differently. That is the testdoing its job, not a routing bug.
2. Isolate auth smoke tests and tolerate unsupported setup commands
What was broken
test_smoke_logoutlogouton the shared pooled connection. That de-authenticated the connection for every later test on the same xdist worker, so unrelated tests failed with authorization errors.test_smoke_rolesInfo,test_smoke_usersInfookexactly withassertSuccessPartial, so an engine returningok: 1(int32) instead of1.0(double) failed a capability probe.drain_fsync_lockinutils/fsync_lock.py,ensure_autocompact_idleinautoCompact/utils/autoCompact_common.py) raised when the command was unsupported. So every test in those folders failed in setup and never ran the command it was meant to probe.What changed
test_smoke_logoutruns on a dedicatedMongoClientbuilt from the test'sconnection_string, so only that client is logged out.test_smoke_rolesInfoandtest_smoke_usersInfoassert withassertCommandSupported, like the capability probes in Make smoke tests capability probes; fix 5 that crash on engine divergence (PR#718 Rebased) #731. The command isunchanged.
command is unsupported (
CommandNotFound59, or 303), since an engine withoutthe command has no state to reset. The test then runs the command and reports
the real result. On an engine that supports the command, the helpers behave
as before.
3. Close server cursors that tests open with raw commands
What was broken
execute_commandandexecute_admin_commandreturn the raw command reply.When that reply holds an open cursor (a
findorlistIndexeswith a smallbatchSize, or anaggregatewith$changeStream), no driver object owns thecursor. Nothing closes it when the test ends, and dropping the test database
doesn't close it on every engine, so it stays open until the server's idle
timeout.
Engines that cap open cursors per instance then reject new cursors. Amazon
DocumentDB's quota is 30 on T3/T4G.medium instances and as low as 6 on a
serverless instance at 0.5 DCU
(quotas,
serverless limits).
Once the cap fills, a later test's setup fails with
Cannot open a new cursor since too many cursors are already opened (code 2), and that test usuallycrashes as described in group 1. Which test hits the cap depends on timing and
test order. So the failures look flaky, and they land on tests that did nothing
wrong.
What changed
The two helpers now record the namespace and id of every open cursor they
return. At test teardown, those cursors are killed with
killCursors:collectionanddatabase_clientfixtures, before the drop;close_leaked_cursors, for tests that use neitherfixture.
Cleanup is best effort. A cursor that is already exhausted or killed comes back
in
cursorsNotFound, and any error is ignored, so cleanup never changes a test'soutcome. Cursors opened through the driver API (
collection.find(),watch())are not touched, because the driver already closes them.
Testing
black,isort,flake8,mypy) on the whole commit range:pass.
pytest -m unit: 152 passed. This includes 7 new cases inframework/test_executor_cursor_tracking.py:$cmd.aggregatenamespace is handled;change streams, sessions, security, administration and others), on the first
revision of this PR: 2,732 passed on
main, and 2,732 passed with all threegroups applied.
mainand 413passed with this change.
execute_command/execute_admin_commandthe test and its helpers issuereturns an
OperationFailure, and every assertion helper records its call andreturns, as an override provider registered through Add opt-in assertion override hook for compatible engines #724 does. On
main, 159tests raise outside the assertion helper (
TypeErroron the error, a re-raisederror, or a fall-through after the assertion). With this change, 1 does:
test_listIndexes_long_name_drop_secondary_indexes, whose driverdrop_indexcall fails only because the injectedcreateIndexesfailurenever created the index. It isn't part of this change.
raised outside the assertion helper on
main(BulkWriteErrorfrom thegeospatial data load), 0 with this change. No test went from passing to
failing; rolesInfo and usersInfo went from failing to passing.
smoke tests on MongoDB: pass, both serially and in parallel.
-n 8: 56,562 results, identical per test onmainand with this change. 54,478 passed, 35 skipped, and 2,049 failed orerrored; all 2,049 are
$search/$vectorSearch/$searchMetateststhat need Atlas Search.
hidden-index and change-stream directories (
-n 8, 2 runs):worse.