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
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@
command=lambda ctx: {"collMod": "oplog.rs", "cappedMax": 1_000},
error_code=INVALID_OPTIONS_ERROR,
msg="collMod should reject cappedMax on the oplog",
marks=(pytest.mark.requires(oplog=True),),
# Only the oplog.rs namespace is needed, not a readable oplog.
marks=(pytest.mark.requires(replication=True),),
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@
command=lambda ctx: {"collMod": "oplog.rs", "cappedSize": 100_000},
error_code=INVALID_OPTIONS_ERROR,
msg="collMod should reject cappedSize on the oplog",
marks=(pytest.mark.requires(oplog=True),),
# Only the oplog.rs namespace is needed, not a readable oplog.
marks=(pytest.mark.requires(replication=True),),
),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from documentdb_tests.framework.property_checks import Eq
from documentdb_tests.framework.test_case import BaseTestCase

pytestmark = pytest.mark.requires(change_streams=True)


# Return the timestamp of the oldest retained oplog entry, so a start point can
# be expressed relative to the live oplog rather than as a static value.
Expand All @@ -36,15 +38,20 @@ def _oldest_oplog_ts(collection) -> Timestamp:
return cast(Timestamp, oldest)


def _seconds_before(ts: Timestamp, seconds: int) -> Timestamp:
return Timestamp(ts.time - seconds, ts.inc)


@dataclass(frozen=True)
class ChangeStreamEarlyStartTestCase(BaseTestCase):
"""Test case for a startAtOperationTime at or before the oldest oplog entry.

Attributes:
compute_start: Receives the timestamp of the oldest retained oplog entry
captured at run time and returns the startAtOperationTime to test, so
the boundary case is expressed relative to the live oplog rather than
as a static value.
compute_start: Receives a zero-argument callable that returns the
timestamp of the oldest retained oplog entry, and returns the
startAtOperationTime to test. The oplog is read only when a case
calls it, so cases with a static start time do not depend on a
readable oplog.
"""

compute_start: Any = None
Expand Down Expand Up @@ -76,22 +83,24 @@ class ChangeStreamEarlyStartTestCase(BaseTestCase):
),
ChangeStreamEarlyStartTestCase(
"oldest_minus_5s",
compute_start=lambda oldest: Timestamp(oldest.time - 5, oldest.inc),
compute_start=lambda oldest: _seconds_before(oldest(), 5),
expected={"ok": Eq(1.0)},
msg="$changeStream should accept a startAtOperationTime five seconds before"
" the oldest retained oplog entry",
# The requires gate reads only the closest requires marker, so a case
# marker must restate the module-level change_streams requirement.
marks=(pytest.mark.requires(change_streams=True, oplog=True),),
),
]


@pytest.mark.requires(change_streams=True)
@pytest.mark.aggregate
@pytest.mark.parametrize("test_case", pytest_params(CHANGESTREAM_EARLY_START_TESTS))
def test_changeStream_early_start_collection_scope(
collection, test_case: ChangeStreamEarlyStartTestCase
):
"""Test $changeStream accepts an early startAtOperationTime on a collection-scoped stream."""
start = test_case.compute_start(_oldest_oplog_ts(collection))
start = test_case.compute_start(lambda: _oldest_oplog_ts(collection))
result = execute_command(
collection,
change_stream_command(
Expand All @@ -101,14 +110,13 @@ def test_changeStream_early_start_collection_scope(
assertResult(result, expected=test_case.expected, msg=test_case.msg, raw_res=True)


@pytest.mark.requires(change_streams=True)
@pytest.mark.aggregate
@pytest.mark.parametrize("test_case", pytest_params(CHANGESTREAM_EARLY_START_TESTS))
def test_changeStream_early_start_database_scope(
collection, test_case: ChangeStreamEarlyStartTestCase
):
"""Test $changeStream accepts an early startAtOperationTime on a database-scoped stream."""
start = test_case.compute_start(_oldest_oplog_ts(collection))
start = test_case.compute_start(lambda: _oldest_oplog_ts(collection))
result = execute_command(
collection,
change_stream_command(
Expand All @@ -120,14 +128,13 @@ def test_changeStream_early_start_database_scope(
assertResult(result, expected=test_case.expected, msg=test_case.msg, raw_res=True)


@pytest.mark.requires(change_streams=True)
@pytest.mark.aggregate
@pytest.mark.parametrize("test_case", pytest_params(CHANGESTREAM_EARLY_START_TESTS))
def test_changeStream_early_start_cluster_scope(
collection, test_case: ChangeStreamEarlyStartTestCase
):
"""Test $changeStream accepts an early startAtOperationTime on a cluster-wide stream."""
start = test_case.compute_start(_oldest_oplog_ts(collection))
start = test_case.compute_start(lambda: _oldest_oplog_ts(collection))
spec = {"startAtOperationTime": start, "allChangesForCluster": True}
# batchSize 0 opens the stream without materializing historical events, whose
# resume tokens can exceed the BSON document size limit on a cluster-wide stream.
Expand Down
10 changes: 4 additions & 6 deletions documentdb_tests/framework/preconditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"reindex": "reIndex is permitted",
"local_rename": "renaming into the unreplicated local database is permitted",
"search": "search and vector search surfaces are available",
"replication": "replication commands are available (applyOps, oplog access)",
"replication": "replication commands are available (applyOps)",
"remote_target": "the server sees the connection as originating from a non-localhost address",
"validate_repair": (
"validate with repair/fixMultikey is permitted and background validation "
Expand Down Expand Up @@ -114,10 +114,9 @@
}
),
# Amazon DocumentDB. A managed, replicated deployment: it presents the
# DocumentDB capability surface and, being backed by a replica set,
# additionally has the replication-dependent capabilities the reference
# server gates behind one (oplog access). Exposed as a single deployment
# form, so its one topology is named ``replica_set``.
# DocumentDB capability surface. It does not expose its replication log as
# local.oplog.rs, so it lacks the oplog capability. Exposed as a single
# deployment form, so its one topology is named ``replica_set``.
("amazon-documentdb", "replica_set"): frozenset(
{
"change_streams",
Expand All @@ -127,7 +126,6 @@
"cluster_time",
"cluster_read_concern",
"quorum_write_concern",
"oplog",
"unforced_compact",
"reindex",
"replication",
Expand Down
Loading