Skip to content

Commit

Permalink
test(NODE-5938): sync retryable writes spec tests (#3996)
Browse files Browse the repository at this point in the history
  • Loading branch information
dariakp committed Feb 15, 2024
1 parent 55203ef commit 10a5c5a
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 84 deletions.
19 changes: 8 additions & 11 deletions test/spec/retryable-writes/unified/bulkWrite-serverErrors.json
Expand Up @@ -3,10 +3,16 @@
"schemaVersion": "1.0",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"minServerVersion": "4.0",
"topologies": [
"replicaset"
]
},
{
"minServerVersion": "4.1.7",
"topologies": [
"sharded"
]
}
],
"createEntities": [
Expand Down Expand Up @@ -55,16 +61,7 @@
"description": "BulkWrite succeeds after retryable writeConcernError in first batch",
"runOnRequirements": [
{
"minServerVersion": "4.0",
"topologies": [
"replicaset"
]
},
{
"minServerVersion": "4.1.7",
"topologies": [
"sharded-replicaset"
]
"minServerVersion": "4.3.1"
}
],
"operations": [
Expand Down
9 changes: 4 additions & 5 deletions test/spec/retryable-writes/unified/bulkWrite-serverErrors.yml
Expand Up @@ -3,8 +3,10 @@ description: "retryable-writes bulkWrite serverErrors"
schemaVersion: "1.0"

runOnRequirements:
- minServerVersion: "3.6"
- minServerVersion: "4.0"
topologies: [ replicaset ]
- minServerVersion: "4.1.7"
topologies: [ sharded ]

createEntities:
- client:
Expand All @@ -30,10 +32,7 @@ initialData:
tests:
- description: "BulkWrite succeeds after retryable writeConcernError in first batch"
runOnRequirements:
- minServerVersion: "4.0"
topologies: [ replicaset ]
- minServerVersion: "4.1.7"
topologies: [ sharded-replicaset ]
- minServerVersion: "4.3.1" # failCommand errorLabels option
operations:
- name: failPoint
object: testRunner
Expand Down
19 changes: 8 additions & 11 deletions test/spec/retryable-writes/unified/insertOne-serverErrors.json
Expand Up @@ -3,10 +3,16 @@
"schemaVersion": "1.0",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"minServerVersion": "4.0",
"topologies": [
"replicaset"
]
},
{
"minServerVersion": "4.1.7",
"topologies": [
"sharded"
]
}
],
"createEntities": [
Expand Down Expand Up @@ -55,16 +61,7 @@
"description": "InsertOne succeeds after retryable writeConcernError",
"runOnRequirements": [
{
"minServerVersion": "4.0",
"topologies": [
"replicaset"
]
},
{
"minServerVersion": "4.1.7",
"topologies": [
"sharded-replicaset"
]
"minServerVersion": "4.3.1"
}
],
"operations": [
Expand Down
9 changes: 4 additions & 5 deletions test/spec/retryable-writes/unified/insertOne-serverErrors.yml
Expand Up @@ -3,8 +3,10 @@ description: "retryable-writes insertOne serverErrors"
schemaVersion: "1.0"

runOnRequirements:
- minServerVersion: "3.6"
- minServerVersion: "4.0"
topologies: [ replicaset ]
- minServerVersion: "4.1.7"
topologies: [ sharded ]

createEntities:
- client:
Expand All @@ -30,10 +32,7 @@ initialData:
tests:
- description: "InsertOne succeeds after retryable writeConcernError"
runOnRequirements:
- minServerVersion: "4.0"
topologies: [ replicaset ]
- minServerVersion: "4.1.7"
topologies: [ sharded-replicaset ]
- minServerVersion: "4.3.1" # failCommand errorLabels option
operations:
- name: failPoint
object: testRunner
Expand Down
59 changes: 34 additions & 25 deletions test/spec/unified-test-format/valid-pass/poc-retryable-writes.json
@@ -1,14 +1,6 @@
{
"description": "poc-retryable-writes",
"schemaVersion": "1.0",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"topologies": [
"replicaset"
]
}
],
"createEntities": [
{
"client": {
Expand Down Expand Up @@ -79,6 +71,14 @@
"tests": [
{
"description": "FindOneAndUpdate is committed on first attempt",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"topologies": [
"replicaset"
]
}
],
"operations": [
{
"name": "failPoint",
Expand Down Expand Up @@ -132,6 +132,14 @@
},
{
"description": "FindOneAndUpdate is not committed on first attempt",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"topologies": [
"replicaset"
]
}
],
"operations": [
{
"name": "failPoint",
Expand Down Expand Up @@ -188,6 +196,14 @@
},
{
"description": "FindOneAndUpdate is never committed",
"runOnRequirements": [
{
"minServerVersion": "3.6",
"topologies": [
"replicaset"
]
}
],
"operations": [
{
"name": "failPoint",
Expand Down Expand Up @@ -245,15 +261,10 @@
"description": "InsertMany succeeds after PrimarySteppedDown",
"runOnRequirements": [
{
"minServerVersion": "4.0",
"topologies": [
"replicaset"
]
},
{
"minServerVersion": "4.1.7",
"minServerVersion": "4.3.1",
"topologies": [
"sharded-replicaset"
"replicaset",
"sharded"
]
}
],
Expand Down Expand Up @@ -345,7 +356,7 @@
{
"minServerVersion": "4.1.7",
"topologies": [
"sharded-replicaset"
"sharded"
]
}
],
Expand Down Expand Up @@ -406,15 +417,10 @@
"description": "InsertOne fails after multiple retryable writeConcernErrors",
"runOnRequirements": [
{
"minServerVersion": "4.0",
"topologies": [
"replicaset"
]
},
{
"minServerVersion": "4.1.7",
"minServerVersion": "4.3.1",
"topologies": [
"sharded-replicaset"
"replicaset",
"sharded"
]
}
],
Expand All @@ -433,6 +439,9 @@
"failCommands": [
"insert"
],
"errorLabels": [
"RetryableWriteError"
],
"writeConcernError": {
"code": 91,
"errmsg": "Replication is being shut down"
Expand Down
32 changes: 18 additions & 14 deletions test/spec/unified-test-format/valid-pass/poc-retryable-writes.yml
Expand Up @@ -2,10 +2,6 @@ description: "poc-retryable-writes"

schemaVersion: "1.0"

runOnRequirements:
- minServerVersion: "3.6"
topologies: [ replicaset ]

createEntities:
- client:
id: &client0 client0
Expand Down Expand Up @@ -42,6 +38,9 @@ initialData:

tests:
- description: "FindOneAndUpdate is committed on first attempt"
runOnRequirements: &onPrimaryTransactionalWrite_requirements
- minServerVersion: "3.6"
topologies: [ replicaset ]
operations:
- name: failPoint
object: testRunner
Expand All @@ -65,6 +64,7 @@ tests:
- { _id: 2, x: 22 }

- description: "FindOneAndUpdate is not committed on first attempt"
runOnRequirements: *onPrimaryTransactionalWrite_requirements
operations:
- name: failPoint
object: testRunner
Expand All @@ -89,6 +89,7 @@ tests:
- { _id: 2, x: 22 }

- description: "FindOneAndUpdate is never committed"
runOnRequirements: *onPrimaryTransactionalWrite_requirements
operations:
- name: failPoint
object: testRunner
Expand All @@ -113,13 +114,9 @@ tests:
- { _id: 2, x: 22 }

- description: "InsertMany succeeds after PrimarySteppedDown"
runOnRequirements: &failCommand_requirements
- minServerVersion: "4.0"
topologies: [ replicaset ]
- minServerVersion: "4.1.7"
# Original test uses "sharded", but retryable writes requires a sharded
# cluster backed by replica sets
topologies: [ sharded-replicaset ]
runOnRequirements:
- minServerVersion: "4.3.1" # failCommand errorLabels option
topologies: [ replicaset, sharded ]
operations:
- name: failPoint
object: testRunner
Expand All @@ -131,7 +128,7 @@ tests:
data:
failCommands: [ insert ]
errorCode: 189 # PrimarySteppedDown
errorLabels: [ RetryableWriteError ]
errorLabels: [ RetryableWriteError ]
- name: insertMany
object: *collection0
arguments:
Expand All @@ -153,7 +150,11 @@ tests:
- { _id: 4, x: 44 }

- description: "InsertOne fails after connection failure when retryWrites option is false"
runOnRequirements: *failCommand_requirements
runOnRequirements: # failCommand
- minServerVersion: "4.0"
topologies: [ replicaset ]
- minServerVersion: "4.1.7"
topologies: [ sharded ]
operations:
- name: failPoint
object: testRunner
Expand Down Expand Up @@ -181,7 +182,9 @@ tests:
- { _id: 2, x: 22 }

- description: "InsertOne fails after multiple retryable writeConcernErrors"
runOnRequirements: *failCommand_requirements
runOnRequirements:
- minServerVersion: "4.3.1" # failCommand errorLabels option
topologies: [ replicaset, sharded ]
operations:
- name: failPoint
object: testRunner
Expand All @@ -192,6 +195,7 @@ tests:
mode: { times: 2 }
data:
failCommands: [ insert ]
errorLabels: [ RetryableWriteError ]
writeConcernError:
code: 91 # ShutdownInProgress
errmsg: "Replication is being shut down"
Expand Down
30 changes: 17 additions & 13 deletions test/tools/unified-spec-runner/unified-utils.ts
Expand Up @@ -41,19 +41,6 @@ export async function topologySatisfies(

let skipReason;

if (r.minServerVersion) {
const minVersion = patchVersion(r.minServerVersion);
ok &&= semverGte(config.version, minVersion);
if (!ok && skipReason == null) {
skipReason = `requires mongodb version greater than ${minVersion}`;
}
}
if (r.maxServerVersion) {
const maxVersion = patchVersion(r.maxServerVersion);
ok &&= semverLte(config.version, maxVersion);
if (!ok && skipReason == null) skipReason = `requires mongodb version less than ${maxVersion}`;
}

if (r.topologies) {
const topologyType = {
Single: 'single',
Expand Down Expand Up @@ -82,6 +69,19 @@ export async function topologySatisfies(
}
}

if (r.minServerVersion) {
const minVersion = patchVersion(r.minServerVersion);
ok &&= semverGte(config.version, minVersion);
if (!ok && skipReason == null) {
skipReason = `requires mongodb version greater than ${minVersion}`;
}
}
if (r.maxServerVersion) {
const maxVersion = patchVersion(r.maxServerVersion);
ok &&= semverLte(config.version, maxVersion);
if (!ok && skipReason == null) skipReason = `requires mongodb version less than ${maxVersion}`;
}

if (r.serverParameters) {
if (!config.parameters) throw new Error('Configuration does not have server parameters');
for (const [name, value] of Object.entries(r.serverParameters)) {
Expand Down Expand Up @@ -146,12 +146,16 @@ export async function topologySatisfies(
}

export async function isAnyRequirementSatisfied(ctx, requirements, client) {
const skipTarget = ctx.currentTest || ctx.test;
const skipReasons = [];
for (const requirement of requirements) {
const met = await topologySatisfies(ctx, requirement, client);
if (met) {
return true;
}
skipReasons.push(skipTarget.skipReason);
}
skipTarget.skipReason = skipReasons.join(' OR ');
return false;
}

Expand Down

0 comments on commit 10a5c5a

Please sign in to comment.