Skip to content

Commit

Permalink
Address changes to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shruti-sridhar committed Jun 21, 2024
1 parent a919001 commit 8634ae3
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
wait_until,
)

import bson
import pymongo
from bson import encode
from bson.codec_options import (
Expand Down Expand Up @@ -106,6 +107,7 @@
from pymongo.synchronous.mongo_client import MongoClient
from pymongo.synchronous.monitoring import ServerHeartbeatListener, ServerHeartbeatStartedEvent
from pymongo.synchronous.pool import (
_MAX_METADATA_SIZE,
_METADATA,
ENV_VAR_K8S,
Connection,
Expand Down Expand Up @@ -362,24 +364,20 @@ def test_metadata(self):
options = client.options
self.assertEqual(options.pool_options.metadata, metadata)
# Test truncating driver info metadata.
client = MongoClient(driver=DriverInfo(name="s" * 512))
client = MongoClient(driver=DriverInfo(name="s" * _MAX_METADATA_SIZE))
options = client.options
self.assertLess(
len(options.pool_options.metadata["driver"]["name"]),
len(_METADATA["driver"]["name"]) + 514,
self.assertLessEqual(
len(bson.encode(options.pool_options.metadata)),
_MAX_METADATA_SIZE,
)
client.admin.command("isMaster")
client = MongoClient(driver=DriverInfo(name="s" * 512, version="s" * 512))
options = client.options
self.assertLess(
len(options.pool_options.metadata["driver"]["name"]),
len(_METADATA["driver"]["name"]) + 514,
client = MongoClient(
driver=DriverInfo(name="s" * _MAX_METADATA_SIZE, version="s" * _MAX_METADATA_SIZE)
)
self.assertLess(
len(options.pool_options.metadata["driver"]["version"]),
len(_METADATA["driver"]["version"]) + 514,
options = client.options
self.assertLessEqual(
len(bson.encode(options.pool_options.metadata)),
_MAX_METADATA_SIZE,
)
client.admin.command("isMaster")

@mock.patch.dict("os.environ", {ENV_VAR_K8S: "1"})
def test_container_metadata(self):
Expand Down

0 comments on commit 8634ae3

Please sign in to comment.