|
| 1 | +import { expect } from 'chai'; |
| 2 | + |
| 3 | +import { type MongoClient } from '../../mongodb'; |
| 4 | + |
| 5 | +const metadata: MongoDBMetadataUI = { |
| 6 | + requires: { |
| 7 | + topology: '!single' |
| 8 | + } |
| 9 | +}; |
| 10 | + |
| 11 | +describe('Transactions Spec Prose', function () { |
| 12 | + let client: MongoClient; |
| 13 | + const started = []; |
| 14 | + |
| 15 | + beforeEach(async function () { |
| 16 | + started.length = 0; |
| 17 | + client = this.configuration.newClient({}, { monitorCommands: true }); |
| 18 | + client.on('commandStarted', ev => started.push(ev)); |
| 19 | + }); |
| 20 | + |
| 21 | + afterEach(async function () { |
| 22 | + await client.close(); |
| 23 | + }); |
| 24 | + |
| 25 | + describe('Options Inside Transaction', function () { |
| 26 | + it( |
| 27 | + '1.0 Write concern not inherited from collection object inside transaction.', |
| 28 | + metadata, |
| 29 | + async () => { |
| 30 | + await client.withSession(async session => { |
| 31 | + session.startTransaction(); |
| 32 | + |
| 33 | + const collection = client.db().collection('txn-test', { writeConcern: { w: 0 } }); |
| 34 | + |
| 35 | + await collection.insertOne({ n: 1 }, { session }); |
| 36 | + |
| 37 | + await session.commitTransaction(); |
| 38 | + }); |
| 39 | + |
| 40 | + const insertStarted = started.find(ev => ev.commandName === 'insert'); |
| 41 | + expect(insertStarted).to.not.have.nested.property('command.writeConcern'); |
| 42 | + |
| 43 | + // not in asked by the spec test but good to check, this is where the WC would be if it wasn't ignored. |
| 44 | + const commitTransactionStarted = started.find(ev => ev.commandName === 'commitTransaction'); |
| 45 | + expect(commitTransactionStarted).to.not.have.nested.property('command.writeConcern'); |
| 46 | + } |
| 47 | + ); |
| 48 | + }); |
| 49 | +}); |
0 commit comments