Skip to content

PYTHON-3088 [v3.13] Update load balancer tests to support dedicated load balancer port #870

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 14 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
7 changes: 6 additions & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ functions:
DISABLE_TEST_COMMANDS=${DISABLE_TEST_COMMANDS} \
ORCHESTRATION_FILE=${ORCHESTRATION_FILE} \
REQUIRE_API_VERSION=${REQUIRE_API_VERSION} \
LOAD_BALANCER=${LOAD_BALANCER} \
bash ${DRIVERS_TOOLS}/.evergreen/run-orchestration.sh
# run-orchestration generates expansion file with the MONGODB_URI for the cluster
- command: expansions.update
Expand Down Expand Up @@ -423,6 +424,7 @@ functions:
fi
if [ -n "${test_loadbalancer}" ]; then
export TEST_LOADBALANCER=1
export LOAD_BALANCER=1
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
export MULTI_MONGOS_LB_URI="${MULTI_MONGOS_LB_URI}"
fi
Expand Down Expand Up @@ -1771,7 +1773,10 @@ tasks:
- func: "bootstrap mongo-orchestration"
vars:
TOPOLOGY: "sharded_cluster"
LOAD_BALANCER: true
- func: "run load-balancer"
vars:
LOAD_BALANCER: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think vars/LOAD_BALANCER is needed for "run load-balancer".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@ShaneHarvey ShaneHarvey Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOAD_BALANCER is not needed for "run tests" either is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ticket states

Drivers must set the LOAD_BALANCER environment variable to "true" in their load balancer test runs and pass the environment variable when invoking run-orchestration.sh.

Which I interpreted as requiring us to set it to true for the test run as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOAD_BALANCER is only needed for run-orchestration.sh. Let's remove it here. Note we can also remove the export LOAD_BALANCER=1 line above.

- func: "run tests"
# }}}
- name: "coverage-report"
Expand Down Expand Up @@ -2971,7 +2976,7 @@ buildvariants:
- matrix_name: "load-balancer"
matrix_spec:
platform: awslinux
mongodb-version: ["5.0", "latest"]
mongodb-version: ["rapid", "latest"]
auth-ssl: "*"
python-version: ["2.7", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "pypy", "pypy3.5", "pypy3.7"]
loadbalancer: "*"
Expand Down
2 changes: 1 addition & 1 deletion bson/json_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def object_hook(dct, json_options=DEFAULT_JSON_OPTIONS):
def _parse_legacy_regex(doc):
pattern = doc["$regex"]
# Check if this is the $regex query operator.
if isinstance(pattern, Regex):
if not isinstance(pattern, (text_type, bytes)):
return doc
flags = 0
# PyMongo always adds $options but some other tools may not.
Expand Down
15 changes: 15 additions & 0 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Changelog
=========

Changes in Version 3.12.3
-------------------------

Issues Resolved
...............

Version 3.12.3 fixes a bug that prevented :meth:`bson.json_util.loads` from
decoding a document with a non-string "$regex" field (`PYTHON-3028`_).

See the `PyMongo 3.12.3 release notes in JIRA`_ for the list of resolved issues
in this release.

.. _PYTHON-3028: https://jira.mongodb.org/browse/PYTHON-3028
.. _PyMongo 3.12.3 release notes in JIRA: https://jira.mongodb.org/secure/ReleaseNote.jspa?projectId=10004&version=32505

Changes in Version 3.12.2
-------------------------

Expand Down
3 changes: 2 additions & 1 deletion doc/examples/uuid.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

.. _handling-uuid-data-example:

Handling UUID Data
Expand All @@ -12,7 +13,7 @@ to MongoDB and retrieve them as native :class:`uuid.UUID` objects::
from uuid import uuid4

# use the 'standard' representation for cross-language compatibility.
client = MongoClient(uuid_representation=UuidRepresentation.STANDARD)
client = MongoClient(uuidRepresentation='standard')
collection = client.get_database('uuid_db').get_collection('uuid_coll')

# remove all documents from collection
Expand Down
2 changes: 1 addition & 1 deletion pymongo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
Deprecated
"""

version_tuple = (3, 12, 2)
version_tuple = (3, 12, 4, '.dev0')

def get_version_string():
if isinstance(version_tuple[-1], str):
Expand Down
6 changes: 3 additions & 3 deletions pymongo/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ def __init__(
speed. 9 is best compression. Defaults to -1.
- `uuidRepresentation`: The BSON representation to use when encoding
from and decoding to instances of :class:`~uuid.UUID`. Valid
values are `pythonLegacy` (the default), `javaLegacy`,
`csharpLegacy`, `standard` and `unspecified`. New applications
should consider setting this to `standard` for cross language
values are the strings: "pythonLegacy" (the default), "javaLegacy",
"csharpLegacy", "standard" and "unspecified". New applications
should consider setting this to "standard" for cross language
compatibility. See :ref:`handling-uuid-data-example` for details.
- `unicode_decode_error_handler`: The error handler to apply when
a Unicode-related error occurs during BSON decoding that would
Expand Down
15 changes: 1 addition & 14 deletions pymongo/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ def _set_keepalive_times(sock):
# main thread, to avoid the deadlock. See PYTHON-607.
u'foo'.encode('idna')

# Remove after PYTHON-2712
_MOCK_SERVICE_ID = False


def _raise_connection_failure(address, error, msg_prefix=None):
"""Convert a socket.error to ConnectionFailure and raise it."""
Expand Down Expand Up @@ -584,14 +581,7 @@ def _hello(self, cluster_time, topology_version,
if auth_ctx:
cmd['speculativeAuthenticate'] = auth_ctx.speculate_command()

doc = self.command('admin', cmd, publish_events=False,
exhaust_allowed=awaitable)
# PYTHON-2712 will remove this topologyVersion fallback logic.
if self.opts.load_balanced and _MOCK_SERVICE_ID:
process_id = doc.get('topologyVersion', {}).get('processId')
doc.setdefault('serviceId', process_id)
if not self.opts.load_balanced:
doc.pop('serviceId', None)
doc = self.command("admin", cmd, publish_events=False, exhaust_allowed=awaitable)
hello = IsMaster(doc, awaitable=awaitable)
self.is_writable = hello.is_writable
self.max_wire_version = hello.max_wire_version
Expand Down Expand Up @@ -629,9 +619,6 @@ def _next_reply(self):
unpacked_docs = reply.unpack_response()
response_doc = unpacked_docs[0]
helpers._check_command_response(response_doc, self.max_wire_version)
# Remove after PYTHON-2712.
if not self.opts.load_balanced:
response_doc.pop('serviceId', None)
return response_doc

def command(self, dbname, spec, secondary_ok=False,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
except ImportError:
_HAVE_SPHINX = False

version = "3.12.2"
version = "3.12.4.dev0"

f = open("README.rst")
try:
Expand Down
11 changes: 4 additions & 7 deletions test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,10 @@
SINGLE_MONGOS_LB_URI = os.environ.get("SINGLE_MONGOS_LB_URI")
MULTI_MONGOS_LB_URI = os.environ.get("MULTI_MONGOS_LB_URI")
if TEST_LOADBALANCER:
# Remove after PYTHON-2712
from pymongo import pool
pool._MOCK_SERVICE_ID = True
res = parse_uri(SINGLE_MONGOS_LB_URI)
host, port = res['nodelist'][0]
db_user = res['username'] or db_user
db_pwd = res['password'] or db_pwd
res = parse_uri(SINGLE_MONGOS_LB_URI or "")
host, port = res["nodelist"][0]
db_user = res["username"] or db_user
db_pwd = res["password"] or db_pwd
elif TEST_SERVERLESS:
TEST_LOADBALANCER = True
res = parse_uri(SINGLE_MONGOS_LB_URI)
Expand Down
9 changes: 9 additions & 0 deletions test/test_json_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ def test_regex(self):
'{"$regex": ".*", "$options": "mx"}',
json_util.dumps(re.compile(b'.*', re.M | re.X)))

def test_regex_validation(self):
non_str_types = [10, {}, []]
docs = [{"$regex": i} for i in non_str_types]
for doc in docs:
self.assertEqual(doc, json_util.loads(json.dumps(doc)))

doc = {"$regex": ""}
self.assertIsInstance(json_util.loads(json.dumps(doc)), Regex)

def test_minkey(self):
self.round_trip({"m": MinKey()})

Expand Down