Repository navigation
Route remaining test-side failures through the assertion - #736
Conversation
…rtion A few tests failed before reaching their assertion, so the real engine result could not be judged or handled by an override provider registered through the assertion hook. test_create_validator_errors[validator_objectid] passed a new random ObjectId on every run, so the command, and any engine reply that echoes it, changed between runs. It now uses a fixed ObjectId; the case still checks that an ObjectId validator is rejected with a type mismatch. test_dropIndexes_event_preserves_specification raised LookupError from index_specification when listIndexes did not return the index. The createIndexes error, or the missing index if createIndexes succeeded, is now the result passed to the test's single assertion. test_dropIndexes_start_after_star_returns_remaining_events indexed drops[1] and opened the startAfter stream unguarded. With fewer than two drop events it now reports the short count through the existing initial_count check, and a failed startAfter open or getMore is passed to the assertion as the result. No assertions are added, and MongoDB results are unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Some engines publish $indexStats accesses.ops and change-stream DDL events asynchronously. A test that reads once right after the query or DDL can then see a zero counter or an empty batch, even though the engine reports the expected state a moment later. The executor gains execute_command_until, which reruns a command until a predicate accepts the result or a bounded timeout (10 seconds by default) passes, and returns the last result. An error result is returned at once. On an engine that reports the state immediately, the command runs exactly once, so MongoDB behaviour is unchanged. The test format validator treats it like the other execute helpers, and framework/test_executor_polling.py covers it with unit tests. Callers: - test_smoke_changeStream_createIndexes reads getMore until the batch is non-empty. - test_indexStats_ops_counter reads $indexStats until accesses.ops >= 1. - test_hidden_behavior.py: test_indexstats_counter waits for the pre-use find to be counted before toggling hidden, and a case that expects a non-zero counter reads until it is non-zero. A case that expects zero still reads once. test_indexstats_nonhidden_accesses_increment_nonzero and test_indexstats_reset_only_affects_toggled_index_b_unchanged read until the index they check reports a use. Every assertion is unchanged; on timeout the last result is asserted exactly as before. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
test_killCursors_response_cursor and test_killCursors_list_indexes_cursor compare the whole killCursors reply, and the expected value embeds the cursor IDs the server assigned in this run. The compared value then differs on every run, so a recorded result for an engine whose reply differs from MongoDB can never match it. cursor_test_case.py gains label_cursor_ids, which replaces the opened cursor ID at position i with "cursor_<i>" in the four killCursors ID lists (cursorsKilled, cursorsNotFound, cursorsAlive, cursorsUnknown). Both tests apply it to the reply and the expected value. Field names, list lengths, order and the ok field are compared exactly as before, and only an ID equal to an opened cursor gets a label, so the tests still prove which opened cursor is reported in which list. An engine error is passed through unchanged. MongoDB results are unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
test_accumulator_mergeObjects_input_forms and test_accumulator_mergeObjects_null_missing read result["cursor"] for a key-order check right after assertSuccess. When the engine returns an error and an override provider handles the assertion, assertSuccess returns and the read then raises TypeError outside the helper. The key order check now runs only on a successful result, so an error reply is judged by the single assertion. The check itself is unchanged. The planCacheClearFilters behavior tests called assertNotError in _set_filters as a setup check, then asserted the final listFilters reply, so a test made two assertion calls and one override entry could not cover both. _set_filters now sends the planCacheSetFilter commands through execute_command and returns the first setup error, which the test passes to its final assertion as the result. If the commands succeed but fewer than two filters are listed, it still raises a plain AssertionError, since the test would prove nothing. Each test now makes exactly one assertion call. MongoDB results are unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
A few more tests failed outside their assertion, read an event that can arrive after the first getMore, or compared a value that embeds this run's cursor ID. test_changeStream_event_structure: the seed insert and the observed mutation ran unguarded, so an engine that rejects an _id type (for example Code or DBRef) raised before the event check. A failed seed, mutation or post-mutation write is now returned as the result and passed to the test's single assertion. test_changeStream_resume: _event_token_of_type now reads the stream with execute_command_until until a batch holds an event of the requested type, so test_expanded_only_token_fails_on_advance no longer fails in setup when the createIndexes event lands after the first getMore. When the event is in the first batch, getMore runs once. test_smoke_changeStream_dropIndexes reads getMore until the batch is non-empty, exactly like the createIndexes smoke test. test_listIndexes_killCursors_succeeds passes a failed listIndexes to the assertion instead of indexing into it, and compares the killCursors reply with the opened cursor ID labelled through label_cursor_ids. test_killCursors_timeseries_cursor never checked its time-series create. When the create was rejected, insert_many made a regular collection and the test passed without a time-series cursor. A failed create is now the result, and the reply is compared with the cursor ID labelled. No assertions are added, and MongoDB results are unchanged. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage, test-framework); effort from diff stats (397+128 LOC, 20 files) If a label is wrong, ping |
eerxuan
left a comment
There was a problem hiding this comment.
Thanks, this looks good. Every changed site still fails when it should, and no error turns into a pass.
[Praise] Nice addition of execute_command_until. It handles state that shows up a little late (index-use counters, change-stream events) without hiding real failures: errors come back at once and are never retried, a timeout hands the last result to the assertion, and on a server that reports the state right away the command runs exactly once. The unit tests in framework/test_executor_polling.py cover each of those paths.
[Praise] Nice catch on test_killCursors_timeseries_cursor: without checking the create, insert_many silently made a regular collection and the test could pass without ever opening a time-series cursor. The label_cursor_ids approach is also neat: it removes run-specific IDs but still proves which cursor lands in which list.
Two small notes inline.
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Summary
Some compatibility tests fail outside their single assertion, read
state once that an engine may publish a moment later, or compare a
value that changes on every run. On an engine whose behaviour differs
from MongoDB, the real result then cannot be judged, or handled by an
override provider registered through the assertion hook. This PR fixes
those tests. MongoDB behaviour and every checked property are
unchanged, and no assertions are added.
Setup failures reach the assertion
test_create_validator_errors[validator_objectid]used a new randomObjectId on every run, so the command and any reply that echoes it
changed between runs. It now uses a fixed ObjectId.
test_dropIndexes_event_preserves_specificationpasses a failedcreateIndexes, or the missing index, to the assertion instead of
raising
LookupError.test_dropIndexes_start_after_star_returns_remaining_eventsreportsfewer than two drop events through the existing
initial_countcheckinstead of an
IndexError, and passes a failedstartAfteropen orgetMore to the assertion.
test_changeStream_event_structure: a rejected seed insert, mutationor post-mutation write (for example on an engine that rejects a Code
or DBRef
_id) is returned as the result instead of raising beforethe event check.
test_listIndexes_killCursors_succeedspasses a failed listIndexes tothe assertion instead of indexing into it.
test_killCursors_timeseries_cursornever checked its time-seriescreate. On an engine that rejects the create,insert_manymade aregular collection and the test passed without a time-series cursor.
A failed create is now the result.
One assertion per test
test_accumulator_mergeObjects_input_formsandtest_accumulator_mergeObjects_null_missingrun their key-order checkonly on a successful result, so an error reply handled by an override
provider no longer raises
TypeErrorafter the assertion.planCacheClearFiltersbehavior tests send their setupplanCacheSetFiltercommands throughexecute_commandand pass thefirst setup error to the final assertion, so each test makes exactly
one assertion call.
Poll state that some engines publish asynchronously
framework/executor.pygainsexecute_command_until, which reruns acommand until a predicate accepts the result or a bounded timeout
(10 seconds by default) passes, and returns the last result. An error
is returned at once. When the state is already there, the command runs
exactly once.
framework/test_executor_polling.pycovers it, and thetest format validator treats it like the other execute helpers.
docs/testing/TEST_FORMAT.mdnow says when to use it: only for statethe server may publish asynchronously, with a predicate that checks the
state is present rather than the asserted value.
Callers:
test_smoke_changeStream_createIndexesandtest_smoke_changeStream_dropIndexesread getMore until the batch isnon-empty.
test_changeStream_resume: the token-capture helper reads until abatch holds an event of the requested type, so
test_expanded_only_token_fails_on_advanceno longer fails in setupwhen the createIndexes event arrives after the first getMore.
test_indexStats_ops_counterreads$indexStatsuntilaccesses.ops >= 1.test_hidden_behavior.pywaits for the counters it checks; a casethat expects zero still reads once.
Stable cursor IDs in compared values
cursor_test_case.pygainslabel_cursor_ids, which replaces theopened cursor ID at position i with
"cursor_<i>"in the fourkillCursors ID lists.
test_killCursors_response_cursor,test_killCursors_list_indexes_cursor,test_killCursors_timeseries_cursorandtest_listIndexes_killCursors_succeedscompare the labelled reply, sothe compared value no longer embeds this run's server-assigned IDs.
Field names, list lengths, order and
okare compared as before, andonly an opened cursor's ID gets a label, so the tests still prove which
cursor lands in which list.
Testing
pre-commit run --all-files(black, isort, flake8, mypy): passed.pytest -m unit: 156 passed.this PR touches (15 files, 247 tests), run on
mainand on thisbranch against separate fresh containers: all pass on both, and the
passing sets are identical.
changed test now reaches its assertion and reports the engine's real
result or error, with no
TypeError,IndexErrororLookupErrorraised outside the assertion helper.