Skip to content

Route remaining test-side failures through the assertion - #736

Merged
eerxuan merged 7 commits into
documentdb:mainfrom
samafarc:fix/close-out-test-side
Nov 16, 2026
Merged

eerxuan merged 7 commits into
documentdb:mainfrom
samafarc:fix/close-out-test-side

Conversation

@samafarc

@samafarc samafarc commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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 random
    ObjectId 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_specification passes a failed
    createIndexes, or the missing index, to the assertion instead of
    raising LookupError.
  • test_dropIndexes_start_after_star_returns_remaining_events reports
    fewer than two drop events through the existing initial_count check
    instead of an IndexError, and passes a failed startAfter open or
    getMore to the assertion.
  • test_changeStream_event_structure: a rejected seed insert, mutation
    or post-mutation write (for example on an engine that rejects a Code
    or DBRef _id) is returned as the result instead of raising before
    the event check.
  • test_listIndexes_killCursors_succeeds passes a failed listIndexes to
    the assertion instead of indexing into it.
  • test_killCursors_timeseries_cursor never checked its time-series
    create. On an engine that rejects the create, insert_many made a
    regular 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_forms and
    test_accumulator_mergeObjects_null_missing run their key-order check
    only on a successful result, so an error reply handled by an override
    provider no longer raises TypeError after the assertion.
  • The planCacheClearFilters behavior tests send their setup
    planCacheSetFilter commands through execute_command and pass the
    first setup error to the final assertion, so each test makes exactly
    one assertion call.

Poll state that some engines publish asynchronously

framework/executor.py 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
is returned at once. When the state is already there, the command runs
exactly once. framework/test_executor_polling.py covers it, and the
test format validator treats it like the other execute helpers.
docs/testing/TEST_FORMAT.md now says when to use it: only for state
the server may publish asynchronously, with a predicate that checks the
state is present rather than the asserted value.

Callers:

  • test_smoke_changeStream_createIndexes and
    test_smoke_changeStream_dropIndexes read getMore until the batch is
    non-empty.
  • test_changeStream_resume: the token-capture helper reads 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 arrives after the first getMore.
  • test_indexStats_ops_counter reads $indexStats until
    accesses.ops >= 1.
  • test_hidden_behavior.py waits for the counters it checks; a case
    that expects zero still reads once.

Stable cursor IDs in compared values

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. test_killCursors_response_cursor,
test_killCursors_list_indexes_cursor,
test_killCursors_timeseries_cursor and
test_listIndexes_killCursors_succeeds compare the labelled reply, so
the compared value no longer embeds this run's server-assigned IDs.
Field names, list lengths, order and ok are compared as before, and
only 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.
  • MongoDB 8.2.4 single-node replica set, every compatibility test file
    this PR touches (15 files, 247 tests), run on main and on this
    branch against separate fresh containers: all pass on both, and the
    passing sets are identical.
  • Against an engine that rejects the affected setup commands, each
    changed test now reaches its assertion and reports the engine's real
    result or error, with no TypeError, IndexError or LookupError
    raised outside the assertion helper.

…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>
@samafarc
samafarc requested a review from a team as a code owner November 11, 2026 20:09
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
@documentdb-triage-tool documentdb-triage-tool Bot added the compatibility test Compatibility test related label Nov 12, 2026
@documentdb-triage-tool

Copy link
Copy Markdown

🤖 Auto-triaged by documentdb-triage-tool.

Applied: compatibility test
Project fields suggested: Component test-coverage · Priority P2 · Effort L · Status Needs Review
Confidence: 0.95 (deterministic)

Reasoning

component from path globs (test-coverage, test-framework); effort from diff stats (397+128 LOC, 20 files)

If a label is wrong, ping @patty-chow so the rules can be tuned. Issues with component labels are left alone; PR component labels are reconciled from changed paths on every run.

@eerxuan eerxuan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread documentdb_tests/framework/executor.py Resolved
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
@documentdb-triage-tool documentdb-triage-tool Bot added the documentation Improvements or additions to documentation label Nov 16, 2026
@eerxuan
eerxuan merged commit 7050c1f into documentdb:main Nov 16, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compatibility test Compatibility test related documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants