Skip to content
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
12 changes: 3 additions & 9 deletions test/mod_wsgi_test/mod_wsgi_test.wsgi
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,13 @@ from pymongo.hello import HelloCompat
from pymongo.mongo_client import MongoClient

client = MongoClient()

# If the deployment is a replica set, connect to the whole set.
replica_set_name = client.admin.command(HelloCompat.LEGACY_CMD).get('setName')
if replica_set_name:
client = MongoClient(replicaSet=replica_set_name)

collection = client.test.test

ndocs = 20

collection.drop()
collection.insert_many([{'i': i} for i in range(ndocs)])
client.close() # Discard main thread's request socket.
Copy link
Member

Choose a reason for hiding this comment

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

I understand why removing this line fixes the test failure but is this line important? It claims to be discarding the "main thread's request socket" which seems like it might be important for the test. This was added in https://jira.mongodb.org/browse/PYTHON-353. Reading through that issue might give a clue.

I suggest we err on the side of caution and do this:

client = MongoClient()
collection = client.test.test
ndocs = 20
collection.drop()
collection.insert_many([{'i': i} for i in range(ndocs)])
client.close()  # Discard main thread's request socket.
client = MongoClient()
collection = client.test.test

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 Oct 5, 2021

Choose a reason for hiding this comment

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

Can you also remove the "# If the deployment is a replica set, connect to the whole set." part like I did in my example? It's no longer needed after PYTHON-2679 (Auto discover replica sets by default).

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.

client.close() # Discard main thread's request socket.
client = MongoClient()
collection = client.test.test

try:
from mod_wsgi import version as mod_wsgi_version
Expand Down