Skip to content

Commit bb46095

Browse files
authored
Merge branch 'NODE-6090' into NODE-6120
2 parents e482c07 + c4e6ab0 commit bb46095

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/sessions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
369369
/**
370370
* Starts a new transaction with the given options.
371371
*
372+
* @remarks
373+
* **IMPORTANT**: Running operations in parallel is not supported during a transaction. The use of `Promise.all`,
374+
* `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is
375+
* undefined behaviour.
376+
*
372377
* @param options - Options for the transaction
373378
*/
374379
startTransaction(options?: TransactionOptions): void {
@@ -443,6 +448,11 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
443448
*
444449
* **IMPORTANT:** This method requires the function passed in to return a Promise. That promise must be made by `await`-ing all operations in such a way that rejections are propagated to the returned promise.
445450
*
451+
* **IMPORTANT:** Running operations in parallel is not supported during a transaction. The use of `Promise.all`,
452+
* `Promise.allSettled`, `Promise.race`, etc to parallelize operations inside a transaction is
453+
* undefined behaviour.
454+
*
455+
*
446456
* @remarks
447457
* - If all operations successfully complete and the `commitTransaction` operation is successful, then the provided function will return the result of the provided function.
448458
* - If the transaction is unable to complete or an error is thrown from within the provided function, then the provided function will throw an error.

test/integration/client-side-operations-timeout/node_csot.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
type Collection,
88
type Db,
99
type FindCursor,
10+
LEGACY_HELLO_COMMAND,
1011
type MongoClient,
1112
MongoOperationTimeoutError
1213
} from '../../mongodb';
@@ -109,38 +110,40 @@ describe('CSOT driver tests', () => {
109110

110111
beforeEach(async function () {
111112
configClient = this.configuration.newClient();
112-
await configClient
113+
const result = await configClient
113114
.db()
114115
.admin()
115116
.command({
116117
configureFailPoint: 'failCommand',
117118
mode: 'alwaysOn',
118119
data: {
119-
failCommands: ['ping'],
120+
failCommands: ['ping', 'hello', LEGACY_HELLO_COMMAND],
120121
blockConnection: true,
121122
blockTimeMS: 10
122123
}
123124
});
125+
expect(result).to.have.property('ok', 1);
124126
});
125127

126128
afterEach(async function () {
127-
await configClient
129+
const result = await configClient
128130
.db()
129131
.admin()
130132
.command({
131133
configureFailPoint: 'failCommand',
132134
mode: 'off',
133135
data: {
134-
failCommands: ['ping'],
136+
failCommands: ['ping', 'hello', LEGACY_HELLO_COMMAND],
135137
blockConnection: true,
136138
blockTimeMS: 10
137139
}
138140
});
141+
expect(result).to.have.property('ok', 1);
139142
await configClient.close();
140143
});
141144

142145
it('throws a MongoOperationTimeoutError', {
143-
metadata: { requires: { mongodb: '>=4.2' } },
146+
metadata: { requires: { mongodb: '>=4.4' } },
144147
test: async function () {
145148
const commandsStarted = [];
146149
client = this.configuration.newClient(undefined, { timeoutMS: 1, monitorCommands: true });
@@ -156,10 +159,10 @@ describe('CSOT driver tests', () => {
156159
e => e
157160
);
158161

159-
expect(commandsStarted).to.have.length(0); // Ensure that we fail before we start the insertOne
160-
161162
expect(maybeError).to.exist;
162163
expect(maybeError).to.be.instanceof(MongoOperationTimeoutError);
164+
165+
expect(commandsStarted).to.have.length(0); // Ensure that we fail before we start the insertOne
163166
}
164167
});
165168
});

0 commit comments

Comments
 (0)