-
Notifications
You must be signed in to change notification settings - Fork 1.8k
test(NODE-6492): add integration tests for transaction write concern behavior #4490
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4413818
test(NODE-6492): add integration tests for transaction write concern …
nbbeeken f52a918
test: reset transaction test collection before each test
nbbeeken c6f83b3
test: skip transactions on sharded clusters for MongoDB versions < 4.2
nbbeeken 13bda33
test: skip currentTest
nbbeeken 0df4118
test: update version check for sharded cluster transactions to includ…
nbbeeken 664cfe9
test: fix skipping tests and add optional chaining for client methods
nbbeeken fd5a174
test: ensure transaction test waits for result
nbbeeken fc9f0e3
test: update transaction test to assert document existence instead of…
nbbeeken bf315db
chore: add a maxServerVersion to CS test failing on latest
nbbeeken bc8202b
remove changes
nbbeeken 80f0c63
chore: remove changes
nbbeeken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { expect } from 'chai'; | ||
import * as semver from 'semver'; | ||
|
||
import { type MongoClient, type ObjectId } from '../../mongodb'; | ||
|
||
const metadata: MongoDBMetadataUI = { | ||
requires: { | ||
topology: '!single' | ||
} | ||
}; | ||
|
||
describe('Transactions Spec Prose', function () { | ||
let client: MongoClient; | ||
const started = []; | ||
|
||
beforeEach(async function () { | ||
if ( | ||
semver.satisfies(this.configuration.version, '<=4.2') && | ||
this.configuration.topologyType === 'Sharded' | ||
) { | ||
if (this.currentTest) { | ||
this.currentTest.skipReason = | ||
'Transactions on sharded clusters are only supported after 4.2'; | ||
this.skip(); | ||
} | ||
} | ||
started.length = 0; | ||
client = this.configuration.newClient({}, { monitorCommands: true }); | ||
|
||
await client | ||
.db() | ||
.collection('txn-test') | ||
.drop() | ||
.catch(() => null); | ||
await client.db().createCollection('txn-test'); | ||
|
||
client.on('commandStarted', ev => started.push(ev)); | ||
}); | ||
|
||
afterEach(async function () { | ||
await client | ||
?.db() | ||
.collection('txn-test') | ||
.drop() | ||
.catch(() => null); | ||
await client?.close(); | ||
}); | ||
|
||
describe('Options Inside Transaction', function () { | ||
it( | ||
'1.0 Write concern not inherited from collection object inside transaction.', | ||
metadata, | ||
async () => { | ||
let _id: ObjectId; | ||
const collection = client.db().collection('txn-test', { writeConcern: { w: 0 } }); | ||
|
||
await client.withSession(async session => { | ||
session.startTransaction(); | ||
_id = (await collection.insertOne({ n: 1 }, { session })).insertedId; | ||
await session.commitTransaction(); | ||
}); | ||
|
||
// keep finding until we get a result, otherwise the test will timeout. | ||
expect(await collection.findOne({ _id })).to.have.property('n', 1); | ||
|
||
const insertStarted = started.find(ev => ev.commandName === 'insert'); | ||
expect(insertStarted).to.not.have.nested.property('command.writeConcern'); | ||
|
||
baileympearson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// not in asked by the spec test but good to check, this is where the WC would be if it wasn't ignored. | ||
const commitTransactionStarted = started.find(ev => ev.commandName === 'commitTransaction'); | ||
expect(commitTransactionStarted).to.not.have.nested.property('command.writeConcern'); | ||
} | ||
); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.