Repository navigation
Remove $documents dependency from expression test helpers (PR#715 Rebased) - #730
Conversation
eerxuan
left a comment
There was a problem hiding this comment.
Summary
Replaces the {aggregate: 1, $documents: [{}]} scaffold in execute_expression / execute_project with insert_one({}) plus an aggregate over the collection, and adds CI hardening (nofile limit, target watchdog, --timeout) in the same PR. I checked how the helpers are used. Across the 471 test files that call them (10,224 parametrized invocations), none pre-populates the collection, and the 10 expressions that mention $$ROOT, $$CURRENT, $$DESCEND or $_id give the same result with or without an _id. CI is green on both mongo targets. The dependency is not fully removed yet (item 1) and the description does not match the diff (item 2).
Critical Issues
-
[Required]
$documentsis still used as a scaffold in 17 places in 9 files, so the description's goal ("run against engines without$documents") is not met.cluster_time/test_cluster_time_clock_progression.py: 407, 418 (_read_cluster_time,_read_cluster_time_with_metadata), 632cluster_time/test_cluster_time_write_paths.py: 654, 693, 805, 847now/test_now_core_semantics.py: 90, 228operator/test_operator_combination_setField_stages.py: 19, 43operator/test_operator_combination_unsetField_stages.py: 81, 104current/test_current_document_and_pipeline.py: 174now/test_now_date_operations.py: 212test_system_variables_now_expression_engine.py: 159data-types/bson_types/types/test_types_string.py: 175
(
lookup/test_lookup_verbose_let_wiring.py:254uses it as a$unionWithdata source; borderline.) 5 of the 11 cluster_time tests this PR rewrites still call_read_cluster_time*, so they still need$documents. The remaining uses in aggregate,$lookup,$facet, stage-position, view and rankFusion tests test$documentsitself and are fine. Please convert the scaffold sites too, or narrow the description. -
[Required] The description lists 2 files; the diff has 7, including
pr-tests.ymlanddev/compose.yaml. The CI changes follow from the helper change (the first CI run of it hit the 6h limit: run 31131591225), so please say that in the description, or move the CI part to its own PR. #715 contains the same five commits and is still open; please close one.
Suggestions
-
[Suggestion] 13 hand-written copies of "aggregate +
$limit: 1+$project" (11 in cluster_time, one in NOW, one in ROOT). REVIEW.md asks for no duplication and helpers inutils/. Add one helper next toexecute_expression, for exampleexecute_expression_single_row(collection, expression). The remaining_read_cluster_time*sites could use it too. -
[Suggestion]
test_root_empty_documentnow uses$replaceWith+$literal, which replaces one stage dependency with two.{$project: {_id: 0}}followed by{$project: {_id: 0, result: "$$ROOT"}}should give the same field-less row using only$project. I have not run it, so please confirm in CI.
Nitpicks
dev/compose.yamlexplains the WiredTiger file-handle behavior twice in the header.
Positive Feedback
- The docstrings state the divergence (
_id,$$ROOT,$$CURRENT). - The watchdog's two-reading rule and baseline check avoid false aborts.
- The 11 cluster_time rewrites match the commit message, and each has a populated collection before its final aggregate.
The expression compatibility tests use a collectionless
`{aggregate: 1}` + `$documents: [{}]` pipeline purely as a scaffold
to feed a single empty document into $project. They do not test
$documents itself, yet they inherit a hard dependency on $documents
support from the shared helpers.
Swap the scaffold for `collection.insert_one({})` plus an aggregate
over the named collection. This is logically identical: both feed
exactly one empty document to $project, so literal expressions and
field references (which resolve to missing against an empty doc)
behave the same. The `collection` fixture is function-scoped, so each
test still runs against a fresh single-document collection.
Updates the two shared helpers (execute_expression, execute_project)
that ~205 files inherit, plus two inline call sites in
test_expressions_combination_variables.py. The _with_insert sibling
helpers are unchanged.
Signed-off-by: Yunxuan Shi <yunxuan@amazon.com>
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
The $documents-removal commit made execute_expression/execute_project
insert a document and aggregate over the whole collection. Two newly
synced system-variable tests relied on the old $documents:[{}] contract
and broke:
- test_root_empty_document: needs a truly field-less input so $$ROOT is
{}, but an inserted doc always carries an auto _id. It now shapes its
own pipeline ($replaceWith:{$literal:{}}) instead of the shared helper.
- test_now_identical_across_getmore_batches: pre-loads 300 docs, so the
whole-collection helper emitted 300 rows. It now uses an inline
pipeline with $limit:1 to collapse to the single expected row.
The shared helpers stay on plain insert_one({}) so the ~359 literal
expression call sites gain no $replaceWith/$limit dependency.
Signed-off-by: Yunxuan Shi <yunxuan@amazon.com>
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
The replica-set test job was hitting GitHub's 6h max execution limit. Root cause: the suite creates and drops tens of thousands of collections per run; WiredTiger keeps an open fd per table it has touched (closing idle ones only very lazily) and, on the replica set, dropped collections become drop-pending idents whose files linger until majority-committed and swept. So the descriptor count tracks total collections created over the run, not the number live at once, and mid-run mongod runs out of descriptors. That surfaces as a WiredTiger WT_PANIC (EMFILE -> fassert) and crashes the server; every remaining test then blocks on connection timeouts and the job crawls for hours. Standalone is unaffected because it reclaims dropped tables immediately and never approaches the ceiling. Two changes: 1. Raise ulimits.nofile to 1048576 (the limit MongoDB's own packaging ships) on both mongod targets. The replica set peaks near 60k open files partway through the suite; 64000 was not enough headroom -- it still crashed at ~31k collections -- so this is set well above the peak. 2. Add a target-death watchdog and a per-test --timeout to the test job so that if a target ever does die mid-run, the job fails in about a minute instead of timing out every remaining test against a dead target for hours. The watchdog sanity-checks its probe first and steps aside if it cannot read a healthy baseline, so it cannot false-abort a healthy run. Signed-off-by: Yunxuan Shi <yunxuan@amazon.com> Signed-off-by: Samar Farooqi <samafarc@amazon.com>
These tests write documents to advance the logical clock (the behavior
under test), then assert a variable/literal expression via execute_expression.
The old helper ran collectionless ($documents: [{}]) so those writes never
affected it. The new helper aggregates over collection.name, so every document
the test wrote becomes an output row -- the assertion expected [{result: X}]
but got one identical row per document.
Each affected assertion evaluates only $$CLUSTER_TIME and Python-computed
literals (never a document field), so the value is identical on any row. Add
{$limit: 1} to collapse the aggregation to the single-row evaluation the
$documents scaffold used to provide -- preserving exactly what each test
verifies without reintroducing the $documents dependency this PR removes.
This is the same shaping the PR already applied to
test_now_identical_across_getmore_batches. The 5 tests whose collection stays
empty are unaffected and still use the helper directly.
Signed-off-by: Yunxuan Shi <yunxuan@amazon.com>
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Watchdog (pr-tests.yml): require two consecutive low container-count
readings before aborting. A single reading of the resource-heavy suite's
`docker compose ps` can transiently error and read as 0, which would
false-abort a healthy run; a real crash stays low across polls, so this
rules out the false abort while adding at most one poll interval to a
genuine fast-fail.
Helper docstrings (utils.py): the insert+aggregate form leaves the input
row with an auto-generated `_id` rather than the field-less row
`$documents: [{}]` produced, so note that an expression reading `$_id`,
`$$ROOT`, or `$$CURRENT` sees that id and diverges (references to any other
missing field are still identical). Documentation only; no behavior change.
Signed-off-by: Yunxuan Shi <yunxuan@amazon.com>
Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Several tests evaluate a final expression over a collection they have already populated, where execute_expression would emit one row per document. They each hand-wrote an aggregate with $limit: 1 and a $project. Add a shared helper for that shape that evaluates the expression once and does not insert, and register it with the test format validator. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
Convert the remaining system variable tests that used $documents only to produce an input row so they run over the test collection instead: - Use execute_expression_single_row for the hand-written single-row aggregates in the $$CLUSTER_TIME and $$NOW tests and for the comparisons that used a $documents row. - Read $$CLUSTER_TIME from a one-document side collection in the same database, seeded once, so reads add nothing to the test's own collection and stay write-free after the first one. - Build the field-less row for $$ROOT and $$CURRENT by inserting a document and excluding _id with $project. - Insert a document and aggregate over the collection for the remaining $$NOW and majority read concern cases. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
- $setField/$unsetField: insert a document and aggregate over the collection; the stages build their output from literals. - Max-length string: pass the string as a $literal, since a document holding it would exceed the maximum document size. - $lookup let wiring: $unionWith the foreign collection instead of a $documents source, and substitute the FOREIGN sentinel in $unionWith.coll. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
The header described WiredTiger's lazy file-handle closing twice. Merge it into one sentence. Signed-off-by: Samar Farooqi <samafarc@amazon.com>
47c791f to
f5fb056
Compare
|
Thanks @eerxuan, all addressed:
Rebased onto current main (10eec47). The touched files plus all of |
|
🤖 Auto-triaged by documentdb-triage-tool. Applied: Reasoningcomponent from path globs (test-coverage, ci, test-framework); effort from diff stats (284+157 LOC, 17 files); LLM: Refactors test helpers and multiple test files to remove If a label is wrong, remove it manually and ping |
Supersedes #715 (rebased onto current
main).Summary
The shared expression helpers and the tests that used
$documentsonly toproduce an input row no longer depend on
$documents. Engines that do notsupport
$documents(or the collectionless{aggregate: 1}form it needs)can now run these tests and fail only on the behavior under test.
Tests that exercise
$documentsitself are unchanged: the$documentssmoke tests, collection-agnostic
aggregatetests (allowDiskUse,maxTimeMS, explain, field, pipeline stages, cursor acceptance),$lookupand
$facetsub-pipeline tests, stage-position tests, view/collModvalidation,
$rankFusioncontent errors, and the$$CLUSTER_TIMEcomposition test that checks a
$documents-sourced pipeline.Changes
Helpers (
operator/expressions/utils/utils.py)execute_expressionandexecute_projectinsert one empty document andaggregate over the test collection instead of using
$documents: [{}].The docstrings note the one difference (the row carries an
_id).execute_expression_single_row(collection, expression): evaluates theexpression once (
$limit: 1+$project) over a collection that alreadyholds documents, without inserting anything. It replaces the hand-written
copies of that pipeline in the
$$CLUSTER_TIMEand$$NOWtests.framework/test_format_validator.py: registers the new helper as one thatruns a command.
Tests converted off
$documentsvariable/system_variables/cluster_time/test_cluster_time_clock_progression.py:final comparisons use
execute_expression_single_row._read_cluster_timeand
_read_cluster_time_with_metadataread from a one-document sidecollection (
<collection>_clock) seeded on the first read, so they addnothing to the test's own collection and later reads are write-free. The
majority read concern case aggregates over the test collection.
cluster_time/test_cluster_time_write_paths.py: the four "value advanced"comparisons use
execute_expression_single_row.now/test_now_core_semantics.py: millisecond sampling, the advance check,and the getMore check use
execute_expression_single_row.now/test_now_date_operations.py,test_system_variables_now_expression_engine.py:insert a document and aggregate over the collection.
root/test_root_core_behavior.py,current/test_current_document_and_pipeline.py:the empty-document cases insert a document and strip it to a field-less row
with
{$project: {_id: 0}}before reading$$ROOT/$$CURRENT.operator/expressions/test_expressions_combination_variables.py,operator/test_operator_combination_setField_stages.py,operator/test_operator_combination_unsetField_stages.py: insert adocument and aggregate over the collection.
data-types/bson_types/types/test_types_string.py: the max-length stringis passed as a
$literal(a document holding it would exceed the maximumdocument size, so it cannot be inserted).
stages/lookup/test_lookup_verbose_let_wiring.py: the$unionWithcaseunions the foreign collection instead of a
$documentssource;lookup/utils/lookup_common.pynow substitutes theFOREIGNsentinel in$unionWith.coll.CI and dev environment (follow from the helper change)
Moving the helpers onto real collections means the suite now creates and
drops far more collections per run. The first CI run of this change hit the
6h job limit (run 31131591225):
the replica set ran out of open files, WiredTiger panicked, and every
remaining test then waited on connection timeouts against a dead server.
dev/compose.yaml: raisesnofileto 1048576 on both MongoDB services(the replica set keeps drop-pending files open and peaks near 60k
descriptors; 64000 was not enough). The header explains why.
.github/workflows/pr-tests.yml: a watchdog aborts the test run when atarget container exits mid-run, so a crash fails the job in about a minute
instead of 6h, and
--timeout=120caps any single hung test.Testing
nofile1048576), all touchedtest files plus the whole
stages/lookupfolder: 550 passed on this branch,550 passed on
main, same test IDs (the$$ROOTempty-document case is nolonger parametrized, so its ID drops the
-empty_documentsuffix).pytest -m unit: 152 passed (same asmain).