Skip to content
Open
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 @@ -36,15 +36,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,10 +81,11 @@ 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",
marks=(pytest.mark.requires(oplog=True),),
),
]

Expand All @@ -91,7 +97,7 @@ 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 @@ -108,7 +114,7 @@ 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 @@ -127,7 +133,7 @@ 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
8 changes: 3 additions & 5 deletions documentdb_tests/framework/preconditions.py
Original file line number Diff line number Diff line change
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