Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Smoke test for $sampleRate expression.
Tests basic $sampleRate expression functionality.
Tests basic $sampleRate match expression functionality.
"""

import pytest
Expand All @@ -12,11 +12,9 @@
pytestmark = pytest.mark.smoke


def test_smoke_sampleRate(collection):
"""Test basic $sampleRate expression behavior."""
collection.insert_many(
[{"_id": 1, "value": 10}, {"_id": 2, "value": 20}, {"_id": 3, "value": 30}]
)
def test_smoke_sampleRate_rate_one(collection):
"""Test $sampleRate: 1.0 returns all documents (deterministic upper boundary)."""
collection.insert_many([{"_id": 1, "val": "a"}, {"_id": 2, "val": "b"}, {"_id": 3, "val": "c"}])

result = execute_command(
collection,
Expand All @@ -27,5 +25,22 @@ def test_smoke_sampleRate(collection):
},
)

expected = [{"_id": 1, "value": 10}, {"_id": 2, "value": 20}, {"_id": 3, "value": 30}]
assertSuccess(result, expected, msg="Should support $sampleRate expression")
expected = [{"_id": 1, "val": "a"}, {"_id": 2, "val": "b"}, {"_id": 3, "val": "c"}]
assertSuccess(result, expected, msg="$sampleRate: 1.0 should return all documents")


def test_smoke_sampleRate_rate_zero(collection):
"""Test $sampleRate: 0.0 returns no documents (deterministic lower boundary)."""
collection.insert_many([{"_id": 1, "val": "a"}, {"_id": 2, "val": "b"}, {"_id": 3, "val": "c"}])

result = execute_command(
collection,
{
"aggregate": collection.name,
"pipeline": [{"$match": {"$sampleRate": 0.0}}],
"cursor": {},
},
)

expected = []
assertSuccess(result, expected, msg="$sampleRate: 0.0 should return no documents")