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

Port transactions spec tests to unified format #1310

Merged
merged 10 commits into from Feb 28, 2024
Merged

Conversation

jyemin
Copy link
Contributor

@jyemin jyemin commented Feb 14, 2024

@jmikola
Copy link
Member

jmikola commented Feb 15, 2024

@jyemin: Looking at the failures related to transactions in the most recent patch build:

@jyemin
Copy link
Contributor Author

jyemin commented Feb 15, 2024

I expect the Java UTR already has that logic as these shouldn't be the first unified tests utilizing distinct and transactions.

It does not have that logic because no tests had been failing. Since I'm only seeing the failures on 4.2 sharded clusters, I am currently planning to skip the two distinct tests in that variant

The other failures are coming from write concern errors on collection drop. @ShaneHarvey suggested that we add a retry of drop until it succeeds. I've done that and now 3.6 and 4.0 sharded clusters are looking good.

@ShaneHarvey
Copy link
Member

ShaneHarvey commented Feb 15, 2024

I'll add that Python's UTR also does not run killAllSessions or distinct since we haven't seen test failures that need those workarounds yet.

@jyemin
Copy link
Contributor Author

jyemin commented Feb 15, 2024

killAllSessions definitely needed for these.

@jyemin jyemin self-assigned this Feb 15, 2024
@jyemin jyemin marked this pull request as ready for review February 15, 2024 23:55
@@ -89,7 +93,16 @@ public static void drop(final MongoNamespace namespace) {
}

public static void drop(final MongoNamespace namespace, final WriteConcern writeConcern) {
new DropCollectionOperation(namespace, writeConcern).execute(getBinding());
boolean success = false;
Copy link
Contributor Author

@jyemin jyemin Feb 15, 2024

Choose a reason for hiding this comment

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

On sharded clusters < 4.2, drop sometimes fails on the first try with a write concern error. Trying again works around it. Same for create below, except with a different exception. :(

I'm curious whether other drivers will run into this. I imagine they will and if so a DRIVERS ticket is probably in order. What do you think @jmikola ?

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 recall encountering a PHPLIB build failure for drop or create in this context. If you want to open a DRIVERS ticket, I'd suggest including the server errors in the description and immediately opening a specs PR with the desired clarification while this is still fresh on your mind.

public class UnifiedTransactionsTest extends UnifiedReactiveStreamsTest {
public UnifiedTransactionsTest(@SuppressWarnings("unused") final String fileDescription,
@SuppressWarnings("unused") final String testDescription,
final String schemaVersion, final BsonArray runOnRequirements, final BsonArray entitiesArray,
final BsonArray initialData, final BsonDocument definition) {
super(schemaVersion, runOnRequirements, entitiesArray, initialData, definition);
assumeFalse(fileDescription.equals("count"));
if (serverVersionLessThan(4, 4) && isSharded()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a way to work around this but since it only affects 4.2, which is EOL, just skip them.

@@ -217,6 +218,9 @@ public void setUp() {
this::createMongoClient,
this::createGridFSBucket,
this::createClientEncryption);

killAllSessions();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is part of the unified test spec but until now wasn't needed.

@@ -838,6 +856,7 @@ private OperationResult executeAssertSessionTransactionState(final BsonDocument
//noinspection SwitchStatementWithTooFewBranches
switch (state) {
case "starting":
case "in_progress":
Copy link
Contributor Author

@jyemin jyemin Feb 16, 2024

Choose a reason for hiding this comment

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

This is the same as is done in the legacy test runner. There doesn't appear to be any difference in observable state between the two.

@@ -449,7 +467,7 @@ private OperationResult executeOperation(final UnifiedTestContext context, final
case "abortTransaction":
return crudHelper.executeAbortTransaction(operation);
case "withTransaction":
return crudHelper.executeWithTransaction(operation, (op, idx) -> assertOperation(context, op, idx));
return crudHelper.executeWithTransaction(operation, (op, idx) -> assertOperationAndThrow(context, op, idx));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is necessary because, unlike a normal operation where we just assert the result (exceptional or not) and then move on to the next one, when an operation is executed in the body of a withTransaction callback, any exception thrown by that operation has to propagate out of the callback, so that it can trigger an abortTransaction instead of a commitTransaction.

@jyemin jyemin marked this pull request as draft February 16, 2024 12:47
@jyemin jyemin marked this pull request as ready for review February 16, 2024 21:57
@stIncMale stIncMale self-requested a review February 28, 2024 00:32
@jyemin
Copy link
Contributor Author

jyemin commented Feb 28, 2024

After merging the fix to JAVA-5334/DRIVER-2816 into this PR, sharded transaction tests started timing out (the drop command would take 90 seconds to complete). I have a fix for that in #1320. Once that is merged into master, I'll merge master into this PR and ensure the tests all pass again.

@jyemin
Copy link
Contributor Author

jyemin commented Feb 28, 2024

Turns out that other PR is not necessary. Just moving killAllSessions to right before initial data creation did the trick.

@jyemin jyemin merged commit d85982d into mongodb:master Feb 28, 2024
54 of 56 checks passed
@jyemin jyemin deleted the j4171 branch February 28, 2024 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants