Skip to content
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

PYTHON-4533 - Convert test/test_sessions.py to async #1733

Merged
merged 5 commits into from
Jul 16, 2024

Conversation

NoahStapp
Copy link
Contributor

No description provided.

Copy link
Contributor

@Jibola Jibola left a comment

Choose a reason for hiding this comment

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

Overall, LGTM. Few comments.

Curious why test/test_sessions.py is seen as a net-new file? Is there a location where it still needs to be deleted?

self.assertIsNone(after_cluster_time)


# class TestClusterTime(IntegrationTest):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this still be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, good catch thanks.

self.assertIsNone(after_cluster_time)


# class TestClusterTime(AsyncIntegrationTest):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

gridfs/asynchronous/grid_file.py Outdated Show resolved Hide resolved
test/asynchronous/test_sessions.py Outdated Show resolved Hide resolved
test/asynchronous/test_sessions.py Outdated Show resolved Hide resolved
_IS_SYNC = False


# Ignore auth commands like saslStart, so we can assert lsid is in all commands.
Copy link
Contributor

Choose a reason for hiding this comment

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

what's an lsid? is it just a session_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lsid is server-side session_id.

await client.aclose()
self.assertEqual(len(client._topology._session_pool), 0)
end_sessions = [e for e in listener.started_events if e.command_name == "endSessions"]
self.assertEqual(len(end_sessions), 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any idea why this is two?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We create two sessions above, so we expect both to close here.

Copy link
Contributor

@Jibola Jibola Jul 16, 2024

Choose a reason for hiding this comment

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

I thought we created _MAX_END_SESSIONS which evaluated to 10000?

test/asynchronous/test_sessions.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Jibola Jibola left a comment

Choose a reason for hiding this comment

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

Checked the sync changes! Main feedback is whether or not the to_list is the correct operation for the cursor. I checked the docs, and I saw for the pymongo.cursor types there should still just be using list(). Let me know if that's changed.

test/test_session.py Show resolved Hide resolved
test/test_session.py Show resolved Hide resolved
test/test_session.py Outdated Show resolved Hide resolved
test/test_session.py Show resolved Hide resolved
test/test_session.py Show resolved Hide resolved
test/test_session.py Show resolved Hide resolved
test/test_session.py Outdated Show resolved Hide resolved
test/test_session.py Show resolved Hide resolved
test/test_session.py Outdated Show resolved Hide resolved
@NoahStapp
Copy link
Contributor Author

Checked the sync changes! Main feedback is whether or not the to_list is the correct operation for the cursor. I checked the docs, and I saw for the pymongo.cursor types there should still just be using list(). Let me know if that's changed.

list() is correct for synchronous cursors, but to_list works for both async and sync cursors, so we use it for our tests to allow the synchro process to automatically stay compatible.

@NoahStapp NoahStapp requested a review from Jibola July 15, 2024 18:58
Jibola
Jibola previously approved these changes Jul 16, 2024
Copy link
Contributor

@Jibola Jibola left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -148,6 +148,7 @@
"test_collection.py",
"test_database.py",
"test_session.py",
"test_transactions.py",
Copy link
Contributor

Choose a reason for hiding this comment

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

Mistaken addition or necessary to make synchro tests pass?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merge artifact, fixed.

@@ -392,13 +404,30 @@ def test_cursor(self):
coll = client.pymongo_test.collection
coll.insert_many([{} for _ in range(1000)])

def lambda_find(session):
Copy link
Member

Choose a reason for hiding this comment

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

This naming schema is a bit odd since none of these are "lambdas". How about we call them "find", "distinct", etc...?

self._test_cursor_helper(
lambda coll, session: coll.find(session=session), lambda cursor: cursor.close()
)
def alambda(coll, session):
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about "lambda".

@NoahStapp NoahStapp merged commit b6f72ad into mongodb:master Jul 16, 2024
30 of 33 checks passed
@NoahStapp NoahStapp deleted the convert-sessions-tests branch July 16, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants