Skip to content

PYTHON-5164 Fix mockupdb TestClusterTime #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2025
Merged
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
49 changes: 5 additions & 44 deletions test/mockupdb/test_cluster_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,50 +123,11 @@ def test_monitor(self):

client = self.simple_client(server.uri, heartbeatFrequencyMS=500)

request = server.receives("ismaster")
# No $clusterTime in first ismaster, only in subsequent ones
self.assertNotIn("$clusterTime", request)
request.ok(reply)

# Next exchange: client returns first clusterTime, we send the second.
request = server.receives("ismaster")
self.assertIn("$clusterTime", request)
self.assertEqual(request["$clusterTime"]["clusterTime"], cluster_time)
cluster_time = Timestamp(cluster_time.time, cluster_time.inc + 1)
reply["$clusterTime"] = {"clusterTime": cluster_time}
request.reply(reply)

# Third exchange: client returns second clusterTime.
request = server.receives("ismaster")
self.assertEqual(request["$clusterTime"]["clusterTime"], cluster_time)

# Return command error with a new clusterTime.
cluster_time = Timestamp(cluster_time.time, cluster_time.inc + 1)
error = {
"ok": 0,
"code": 211,
"errmsg": "Cache Reader No keys found for HMAC ...",
"$clusterTime": {"clusterTime": cluster_time},
}
request.reply(error)

# PyMongo 3.11+ closes the monitoring connection on command errors.

# Fourth exchange: the Monitor closes the connection and runs the
# handshake on a new connection.
request = server.receives("ismaster")
# No $clusterTime in first ismaster, only in subsequent ones
self.assertNotIn("$clusterTime", request)

# Reply without $clusterTime.
reply.pop("$clusterTime")
request.reply(reply)

# Fifth exchange: the Monitor attempt uses the clusterTime from
# the previous isMaster error.
request = server.receives("ismaster")
self.assertEqual(request["$clusterTime"]["clusterTime"], cluster_time)
request.reply(reply)
for _ in range(3):
request = server.receives("ismaster")
# No $clusterTime in heartbeats or handshakes.
self.assertNotIn("$clusterTime", request)
request.ok(reply)
client.close()

def test_collection_bulk_error(self):
Expand Down
Loading