Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,51 @@ When targets are discovered automatically (running `pytest` with no
`--connection-string`), each test runs against every discovered target it
applies to, so no manual selection is needed.

### Reference Version and Spec Versions

Expected results are pinned to MongoDB 8.2.4, the version CI runs against.
Every test except smoke tests always runs and expects the 8.2.4 answer,
whatever `--spec-version` is set to.

Only smoke tests (`pytest.mark.smoke`) can select a target minor version,
with `--spec-version` (`8.0`, `8.2` or `8.3`, default `8.2`). A smoke test for
a feature added in a later version declares it with the `requires` marker:

```python
pytestmark = [pytest.mark.smoke, pytest.mark.requires(spec_since="8.3")]
```

`spec_until` works the same way for a feature a later version removed. A smoke
test with no spec gate runs under every spec version. There is no `8.1` spec
version: a feature added in 8.1 uses `spec_since="8.2"`. A spec gate on a test
that is not a smoke test is a collection error.

Out-of-scope smoke tests are deselected and listed, with the gate that excluded
them, in the report's `.deselected.json` sidecar. The JSON report records the
run's spec version and each target's server version under `run`.

The gate can be set on a smoke test, a smoke test file (`pytestmark`, as above)
or a folder that holds only smoke tests, from the folder's `conftest.py`:

```python
from documentdb_tests.framework.preconditions import spec_gate_folder

pytest_collection_modifyitems = spec_gate_folder(__file__, spec_since="8.3")
```

Gates combine with capability gates such as `requires(change_streams=True)`;
on the same key the closest level wins.

```bash
# Run the smoke tests for spec 8.3 against the 8.3 dev server
docker compose -f dev/compose.yaml --profile mongo-standalone-8.3 up -d --wait
pytest -m smoke --connection-string mongodb://localhost:27019 --engine-name mongodb --spec-version 8.3

# Run the smoke tests for spec 8.0 against the 8.0 dev server
docker compose -f dev/compose.yaml --profile mongo-standalone-8.0 up -d --wait
pytest -m smoke --connection-string mongodb://localhost:27020 --engine-name mongodb --spec-version 8.0
```

## Writing Tests

### Basic Test Structure
Expand Down
44 changes: 42 additions & 2 deletions dev/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ services:
soft: 1048576
hard: 1048576
ports:
- "27017:27017"
- "127.0.0.1:27017:27017"
healthcheck:
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ping:1}).ok"]
interval: 5s
Expand All @@ -75,6 +75,46 @@ services:
x-test-target:
engine: mongodb

# mongo-standalone-8.0: a standalone server on the 8.0 release, for runs
# scoped to the 8.0 spec (smoke tests only, --spec-version 8.0). It has no
# x-test-target, so it is not auto-discovered and not part of the CI
# matrix; point pytest at it explicitly:
#
# docker compose -f dev/compose.yaml --profile mongo-standalone-8.0 up -d --wait
# pytest -m smoke --connection-string mongodb://localhost:27020 --engine-name mongodb \
# --spec-version 8.0
mongo-standalone-8.0:
image: mongo:8.0.38
profiles: ["mongo-standalone-8.0"]
command: ["--wiredTigerCacheSizeGB", "1.5"]
ports:
- "127.0.0.1:27020:27017"
healthcheck:
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ping:1}).ok"]
interval: 5s
timeout: 5s
retries: 10

# mongo-standalone-8.3: a standalone server on the 8.3 release, for runs
# scoped to the 8.3 spec (smoke tests only, --spec-version 8.3). It has no
# x-test-target, so it is not auto-discovered and not part of the CI
# matrix; point pytest at it explicitly:
#
# docker compose -f dev/compose.yaml --profile mongo-standalone-8.3 up -d --wait
# pytest -m smoke --connection-string mongodb://localhost:27019 --engine-name mongodb \
# --spec-version 8.3
mongo-standalone-8.3:
image: mongo:8.3.13
profiles: ["mongo-standalone-8.3"]
command: ["--wiredTigerCacheSizeGB", "1.5"]
ports:
- "127.0.0.1:27019:27017"
healthcheck:
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ping:1}).ok"]
interval: 5s
timeout: 5s
retries: 10

# mongo-replset: a single-node replica set. Provides capabilities the
# reference server gates behind a replica set (change streams, transactions,
# queryable encryption, cluster-wide admin). Connect with directConnection=true.
Expand Down Expand Up @@ -110,7 +150,7 @@ services:
soft: 1048576
hard: 1048576
ports:
- "27018:27017"
- "127.0.0.1:27018:27017"
healthcheck:
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ping:1}).ok"]
interval: 5s
Expand Down
1 change: 1 addition & 0 deletions docs/REVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Follow every rule in [`FOLDER_STRUCTURE.md`](testing/FOLDER_STRUCTURE.md). Addit
- [ ] Type annotations on helper functions
- [ ] Order-independent output uses `ignore_doc_order=True`
- [ ] Tests that depend on an environment capability are gated with `@pytest.mark.requires(<capability>=<bool>)` (e.g. `requires(change_streams=True)`), not a topology marker
- [ ] Expected results match MongoDB 8.2.4 (the CI target). Only smoke tests may carry a spec gate: a smoke test for a feature added after 8.0 uses `requires(spec_since="<version>")` (8.1 features use `"8.2"`; see README "Reference Version and Spec Versions"), not an `engine_xfail` for the reference server. Other tests never get a spec gate
- [ ] Tests that cannot run in parallel are tagged `@pytest.mark.no_parallel`
- [ ] Tests where MongoDB itself fails are tagged with `engine_xfail` (not skipped)
- [ ] Tests with non-deterministic output (e.g. `$rand`, `$sample`, server timestamps) assert structure/bounds, not exact values
Expand Down
4 changes: 2 additions & 2 deletions docs/SMOKE_TEST_NOTE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## Overview

Smoke test files: 456
Feature tree entries: 469
Smoke test files: 487
Feature tree entries: 499
Missing: 13

## Missing Features (13)
Expand Down
30 changes: 30 additions & 0 deletions docs/feature-tree.csv
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ core,operator,expressions,conditional,-,ifNull
core,operator,expressions,conditional,-,switch
core,operator,expressions,custom,-,function
core,operator,expressions,custom,-,operator_accumulator
core,operator,expressions,date,-,currentDate
core,operator,expressions,date,-,dateAdd
core,operator,expressions,date,-,dateDiff
core,operator,expressions,date,-,dateFromParts
Expand All @@ -156,7 +157,10 @@ core,operator,expressions,date,-,week
core,operator,expressions,date,-,year
core,operator,expressions,misc,-,binarySize
core,operator,expressions,misc,-,bsonSize
core,operator,expressions,misc,-,createObjectId
core,operator,expressions,misc,-,getField
core,operator,expressions,misc,-,hash
core,operator,expressions,misc,-,hexHash
core,operator,expressions,misc,-,rand
core,operator,expressions,misc,-,sampleRate
core,operator,expressions,misc,-,toHashedIndexKey
Expand Down Expand Up @@ -208,19 +212,37 @@ core,operator,expressions,trigonometry,-,sinh
core,operator,expressions,trigonometry,-,tan
core,operator,expressions,trigonometry,-,tanh
core,operator,expressions,type,-,convert
core,operator,expressions,type,-,deserializeEJSON
core,operator,expressions,type,-,isNumber
core,operator,expressions,type,-,serializeEJSON
core,operator,expressions,type,-,subtype
core,operator,expressions,type,-,toArray
core,operator,expressions,type,-,toBool
core,operator,expressions,type,-,toDecimal
core,operator,expressions,type,-,toDouble
core,operator,expressions,type,-,toInt
core,operator,expressions,type,-,toLong
core,operator,expressions,type,-,toObject
core,operator,expressions,type,-,toObjectId
core,operator,expressions,type,-,toUUID
core,operator,expressions,type,-,toDate
core,operator,expressions,type,-,type
core,operator,expressions,variable,-,let
core,operator,expressions,variable,system-variables,cluster_time
core,operator,expressions,variable,system-variables,current
core,operator,expressions,variable,system-variables,descend
core,operator,expressions,variable,system-variables,idx
core,operator,expressions,variable,system-variables,keep
core,operator,expressions,variable,system-variables,now
core,operator,expressions,variable,system-variables,prune
core,operator,expressions,variable,system-variables,remove
core,operator,expressions,variable,system-variables,root
core,operator,expressions,variable,system-variables,user_roles
core,operator,expressions,vector-similarity,-,similarityCosine
core,operator,expressions,vector-similarity,-,similarityDotProduct
core,operator,expressions,vector-similarity,-,similarityEuclidean
core,operator,projection,-,-,elemMatch
core,operator,projection,-,-,meta
core,operator,projection,-,-,positional
core,operator,projection,-,-,slice
core,operator,query,-,-,text
Expand Down Expand Up @@ -292,6 +314,8 @@ core,operator,stages,-,-,redact
core,operator,stages,-,-,replaceRoot
core,operator,stages,-,-,replaceWith
core,operator,stages,-,-,sample
core,operator,stages,-,-,score
core,operator,stages,-,-,scoreFusion
core,operator,stages,-,-,search
core,operator,stages,-,-,searchMeta
core,operator,stages,-,-,set
Expand Down Expand Up @@ -341,14 +365,20 @@ core,operator,window,-,-,derivative
core,operator,window,-,-,documentNumber
core,operator,window,-,-,expMovingAvg
core,operator,window,-,-,first
core,operator,window,-,-,firstN
core,operator,window,-,-,integral
core,operator,window,-,-,last
core,operator,window,-,-,lastN
core,operator,window,-,-,linearFill
core,operator,window,-,-,locf
core,operator,window,-,-,max
core,operator,window,-,-,maxN
core,operator,window,-,-,median
core,operator,window,-,-,mergeObjects
core,operator,window,-,-,min
core,operator,window,-,-,minMaxScaler
core,operator,window,-,-,minN
core,operator,window,-,-,percentile
core,operator,window,-,-,push
core,operator,window,-,-,rank
core,operator,window,-,-,shift
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from documentdb_tests.framework.assertions import assertSuccess
from documentdb_tests.framework.executor import execute_command

pytestmark = pytest.mark.smoke
pytestmark = [pytest.mark.smoke, pytest.mark.requires(spec_since="8.2")]


def test_smoke_accumulator_concatArrays(collection):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from documentdb_tests.framework.assertions import assertSuccess
from documentdb_tests.framework.executor import execute_command

pytestmark = pytest.mark.smoke
pytestmark = [pytest.mark.smoke, pytest.mark.requires(spec_since="8.2")]


def test_smoke_accumulator_setUnion(collection):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from documentdb_tests.framework.assertions import assertSuccess
from documentdb_tests.framework.executor import execute_command

pytestmark = pytest.mark.smoke
pytestmark = [pytest.mark.smoke, pytest.mark.requires(spec_since="8.2")]


def test_smoke_expression_sigmoid(collection):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Every test in this folder covers behavior added in spec 8.3."""

from documentdb_tests.framework.preconditions import spec_gate_folder

pytest_collection_modifyitems = spec_gate_folder(__file__, spec_since="8.3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Smoke test for the $currentDate aggregation expression: the engine accepts it."""

import pytest

from documentdb_tests.framework.assertions import assertCommandSupported
from documentdb_tests.framework.executor import execute_command

pytestmark = pytest.mark.smoke


def test_smoke_currentDate(collection):
"""Test the engine accepts $currentDate as an aggregation expression."""
collection.insert_one({"_id": 1})

result = execute_command(
collection,
{
"aggregate": collection.name,
"pipeline": [{"$project": {"_id": 0, "result": {"$currentDate": {}}}}],
"cursor": {},
},
)

assertCommandSupported(result, msg="Should support $currentDate expression")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Every test in this folder covers behavior added in spec 8.3."""

from documentdb_tests.framework.preconditions import spec_gate_folder

pytest_collection_modifyitems = spec_gate_folder(__file__, spec_since="8.3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Smoke test for the $createObjectId expression (new in 8.3): the engine accepts it."""

import pytest

from documentdb_tests.framework.assertions import assertCommandSupported
from documentdb_tests.framework.executor import execute_command

pytestmark = pytest.mark.smoke


def test_smoke_createObjectId(collection):
"""Test the engine accepts the $createObjectId expression."""
collection.insert_one({"_id": 1})

result = execute_command(
collection,
{
"aggregate": collection.name,
"pipeline": [{"$project": {"_id": 0, "result": {"$createObjectId": {}}}}],
"cursor": {},
},
)

assertCommandSupported(result, msg="Should support $createObjectId expression")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Every test in this folder covers behavior added in spec 8.3."""

from documentdb_tests.framework.preconditions import spec_gate_folder

pytest_collection_modifyitems = spec_gate_folder(__file__, spec_since="8.3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Smoke test for the $hash expression (new in 8.3): the engine accepts it."""

import pytest

from documentdb_tests.framework.assertions import assertCommandSupported
from documentdb_tests.framework.executor import execute_command

pytestmark = pytest.mark.smoke


def test_smoke_hash(collection):
"""Test the engine accepts the $hash expression."""
collection.insert_one({"_id": 1, "s": "abc"})

result = execute_command(
collection,
{
"aggregate": collection.name,
"pipeline": [
{
"$project": {
"_id": 0,
"result": {"$hash": {"input": "$s", "algorithm": "sha256"}},
}
}
],
"cursor": {},
},
)

assertCommandSupported(result, msg="Should support $hash expression")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Every test in this folder covers behavior added in spec 8.3."""

from documentdb_tests.framework.preconditions import spec_gate_folder

pytest_collection_modifyitems = spec_gate_folder(__file__, spec_since="8.3")
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Smoke test for the $hexHash expression (new in 8.3): the engine accepts it."""

import pytest

from documentdb_tests.framework.assertions import assertCommandSupported
from documentdb_tests.framework.executor import execute_command

pytestmark = pytest.mark.smoke


def test_smoke_hexHash(collection):
"""Test the engine accepts the $hexHash expression."""
collection.insert_one({"_id": 1, "s": "abc"})

result = execute_command(
collection,
{
"aggregate": collection.name,
"pipeline": [
{
"$project": {
"_id": 0,
"result": {"$hexHash": {"input": "$s", "algorithm": "sha256"}},
}
}
],
"cursor": {},
},
)

assertCommandSupported(result, msg="Should support $hexHash expression")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Every test in this folder covers behavior added in spec 8.3."""

from documentdb_tests.framework.preconditions import spec_gate_folder

pytest_collection_modifyitems = spec_gate_folder(__file__, spec_since="8.3")
Loading
Loading