Skip to content

PYTHON-2723 Convert transactions spec tests to unified test format #1543

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 11 commits into from
Mar 26, 2024

Conversation

blink1073
Copy link
Member

No description provided.

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

The tests are taking a long time because many are waiting 60 seconds for open transactions to time out. We need to add killAllSessions as described here: https://github.com/mongodb/specifications/blob/master/source/unified-test-format/unified-test-format.md#terminating-open-transactions

Note we already do this in the legacy txn test runner here:

def kill_all_sessions(self):
clients = self.mongos_clients if self.mongos_clients else [self.client]
for client in clients:
try:
client.admin.command("killAllSessions", [])
except OperationFailure:
# "operation was interrupted" by killing the command's
# own session.
pass

@blink1073 blink1073 requested a review from ShaneHarvey March 26, 2024 01:55
@blink1073 blink1073 marked this pull request as ready for review March 26, 2024 01:55
@blink1073
Copy link
Member Author

evergreen retry

@blink1073 blink1073 closed this Mar 26, 2024
@blink1073 blink1073 reopened this Mar 26, 2024
@blink1073
Copy link
Member Author

evergreen retry

@blink1073
Copy link
Member Author

Evergreen is failing to create the patch build because the diff is too big, here is a manual patch: https://spruce.mongodb.com/version/66022b707612660007a780f0/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC

@blink1073
Copy link
Member Author

I verified that the transaction tests are run on serverless.

@@ -1229,6 +1235,16 @@ def _databaseOperation_createCommandCursor(self, target, **kwargs):

return cursor

def kill_all_sessions(self):
if getattr(self, "client", None) is None:
Copy link
Member

Choose a reason for hiding this comment

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

Why would client be None here? Should we be using the client_context.client?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was None on two of the tests that were testing the spec runner itself without creating a client.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see it's TestCreateEntities.

if getattr(self, "client", None) is None:
return
try:
self.client.admin.command("killAllSessions", [])
Copy link
Member

Choose a reason for hiding this comment

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

In the legacy runner, we would run this on all mongoses. I think we should do that here too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find the equivalent of mongos_clients, it looks like all clients go through this line:

self[spec["id"]] = client

Copy link
Member

Choose a reason for hiding this comment

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

We'll need to create those clients like is done in the legacy txn tests:

cls.mongos_clients.append(single_client("{}:{}".format(*address)))

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

else:
result = self.run_entity_operation(op)
if isinstance(result, Exception):
raise result
Copy link
Member

Choose a reason for hiding this comment

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

Why re-raise this exception after ignoreResultAndError or expectError? Does the spec say to do that somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, "Ensure that neither ignoreResultAndError nor expectError interfere with propagating exceptions from a callback operation to withTransaction"

Copy link
Member

Choose a reason for hiding this comment

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

Where is that written? That line doesn't appear in the spec repo.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is from the ticket description, there is more discussion on the original spec PR.

@blink1073 blink1073 requested a review from ShaneHarvey March 26, 2024 19:07
@blink1073
Copy link
Member Author

@ShaneHarvey
Copy link
Member

What's up with the "@evergreen-ci-prod evergreen — Evergreen error" in the check?

@ShaneHarvey
Copy link
Member

ShaneHarvey commented Mar 26, 2024

 [2024/03/26 13:15:00.064] ERROR: failed on setup with "pymongo.errors.ConfigurationError: Cannot specify directConnection=true with loadBalanced=true" ()
 [2024/03/26 13:15:00.064] cls = <class 'test.test_auth_spec.TestUnifiedReauthenticateWithRetry'>
 [2024/03/26 13:15:00.064]     @classmethod
 [2024/03/26 13:15:00.064]     def setUpClass(cls):
 [2024/03/26 13:15:00.064]         # super call creates internal client cls.client
 [2024/03/26 13:15:00.064]         super().setUpClass()
 [2024/03/26 13:15:00.064]         # process file-level runOnRequirements
 [2024/03/26 13:15:00.064]         run_on_spec = cls.TEST_SPEC.get("runOnRequirements", [])
 [2024/03/26 13:15:00.064]         if not cls.should_run_on(run_on_spec):
 [2024/03/26 13:15:00.064]             raise unittest.SkipTest(f"{cls.__name__} runOnRequirements not satisfied")
 [2024/03/26 13:15:00.064]     
 [2024/03/26 13:15:00.064]         # Handle mongos_clients for transactions tests.
 [2024/03/26 13:15:00.064]         cls.mongos_clients = []
 [2024/03/26 13:15:00.064]         if client_context.supports_transactions():
 [2024/03/26 13:15:00.064]             for address in client_context.mongoses:
 [2024/03/26 13:15:00.064] >               cls.mongos_clients.append(single_client("{}:{}".format(*address)))
 [2024/03/26 13:15:00.064] test/unified_format.py:1022: 
 [2024/03/26 13:15:00.064] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 [2024/03/26 13:15:00.064] test/utils.py:604: in single_client
 [2024/03/26 13:15:00.064]     return _mongo_client(h, p, directConnection=True, **kwargs)
 [2024/03/26 13:15:00.064] test/utils.py:594: in _mongo_client
 [2024/03/26 13:15:00.064]     return MongoClient(uri, port, **client_options)
 [2024/03/26 13:15:00.064] pymongo/mongo_client.py:825: in __init__
 [2024/03/26 13:15:00.064]     _check_options(seeds, opts)
 [2024/03/26 13:15:00.064] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 [2024/03/26 13:15:00.064] nodes = {('32071-drivertest-lb.3x79d.mongodb-dev.net', 27017)}
 [2024/03/26 13:15:00.064] options = {'loadBalanced': True, 'compressors': ['zlib'], 'tls': True, 'directConnection': True, 'username': 'drivers-testing', 'password': '47l0tpPl13dobvHF', 'document_class': <class 'dict'>, 'tz_aware': False, 'connect': True}
 [2024/03/26 13:15:00.064]     def _check_options(nodes: Sized, options: Mapping[str, Any]) -> None:
 [2024/03/26 13:15:00.064]         # Ensure directConnection was not True if there are multiple seeds.
 [2024/03/26 13:15:00.064]         if len(nodes) > 1 and options.get("directconnection"):
 [2024/03/26 13:15:00.064]             raise ConfigurationError("Cannot specify multiple hosts with directConnection=true")
 [2024/03/26 13:15:00.064]     
 [2024/03/26 13:15:00.064]         if options.get("loadbalanced"):
 [2024/03/26 13:15:00.064]             if len(nodes) > 1:
 [2024/03/26 13:15:00.064]                 raise ConfigurationError("Cannot specify multiple hosts with loadBalanced=true")
 [2024/03/26 13:15:00.064]             if options.get("directconnection"):
 [2024/03/26 13:15:00.064] >               raise ConfigurationError("Cannot specify directConnection=true with loadBalanced=true")
 [2024/03/26 13:15:00.064] E               pymongo.errors.ConfigurationError: Cannot specify directConnection=true with loadBalanced=true
 [2024/03/26 13:15:00.064] pymongo/uri_parser.py:403: ConfigurationError

Looks like the mongos_clients logic needs to be skipped on serverless+loadBalanced clusters.

@blink1073
Copy link
Member Author

What's up with the "@evergreen-ci-prod evergreen — Evergreen error" in the check?

The diff is too big, they're working on a fix where it will at least submit the patch even if the diff part fails.

@blink1073
Copy link
Member Author

blink1073 commented Mar 26, 2024

Looks like the mongos_clients logic needs to be skipped on serverless+loadBalanced clusters.

Done

https://spruce.mongodb.com/version/66033b7a8b69b6000726fb32/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC

Copy link
Member

@ShaneHarvey ShaneHarvey left a comment

Choose a reason for hiding this comment

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

LGTM

@blink1073 blink1073 merged commit e37394d into mongodb:master Mar 26, 2024
66 of 67 checks passed
@blink1073 blink1073 deleted the PYTHON-2723 branch March 26, 2024 22:28
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.

2 participants