Skip to content

Commit 419a848

Browse files
fix(NODE-6377): Remove noResponse option
temp temp2
1 parent 6104c57 commit 419a848

File tree

7 files changed

+27
-37
lines changed

7 files changed

+27
-37
lines changed

src/cmap/connection.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ export interface CommandOptions extends BSONSerializeOptions {
8181
/** Session to use for the operation */
8282
session?: ClientSession;
8383
documentsReturnedIn?: string;
84-
noResponse?: boolean;
8584
omitReadPreference?: boolean;
8685

8786
// TODO(NODE-2802): Currently the CommandOptions take a property willRetryWrite which is a hint
@@ -94,6 +93,9 @@ export interface CommandOptions extends BSONSerializeOptions {
9493
writeConcern?: WriteConcern;
9594

9695
directConnection?: boolean;
96+
97+
// Triggers fire-and-forget protocol for commands that don't support WriteConcern
98+
moreToCome?: boolean;
9799
}
98100

99101
/** @public */
@@ -439,7 +441,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
439441
zlibCompressionLevel: this.description.zlibCompressionLevel
440442
});
441443

442-
if (options.noResponse || message.moreToCome) {
444+
if (message.moreToCome) {
443445
yield MongoDBResponse.empty;
444446
return;
445447
}
@@ -527,11 +529,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
527529
new CommandSucceededEvent(
528530
this,
529531
message,
530-
options.noResponse
531-
? undefined
532-
: message.moreToCome
533-
? { ok: 1 }
534-
: (object ??= document.toObject(bsonOptions)),
532+
message.moreToCome ? { ok: 1 } : (object ??= document.toObject(bsonOptions)),
535533
started,
536534
this.description.serverConnectionId
537535
)

src/mongo_client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ export class MongoClient extends TypedEventEmitter<MongoClientEvents> implements
628628
this,
629629
new RunAdminCommandOperation(
630630
{ endSessions },
631-
{ readPreference: ReadPreference.primaryPreferred, noResponse: true }
631+
{ readPreference: ReadPreference.primaryPreferred, moreToCome: true }
632632
)
633633
);
634634
} catch (error) {

src/operations/command.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export interface CommandOperationOptions
5555
// Admin command overrides.
5656
dbName?: string;
5757
authdb?: string;
58-
noResponse?: boolean;
5958
}
6059

6160
/** @internal */

src/operations/run_command.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { type TODO_NODE_3286 } from '../mongo_types';
55
import type { ReadPreferenceLike } from '../read_preference';
66
import type { Server } from '../sdam/server';
77
import type { ClientSession } from '../sessions';
8+
import type { WriteConcern } from '../write_concern';
89
import { MongoDBNamespace } from '../utils';
9-
import { AbstractOperation } from './operation';
10+
import { Aspect, defineAspects, AbstractOperation } from './operation';
1011

1112
/** @public */
1213
export type RunCommandOptions = {
@@ -51,7 +52,7 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
5152
constructor(
5253
public command: Document,
5354
public override options: RunCommandOptions & {
54-
noResponse?: boolean;
55+
moreToCome?: boolean;
5556
bypassPinningCheck?: boolean;
5657
}
5758
) {
@@ -72,4 +73,4 @@ export class RunAdminCommandOperation<T = Document> extends AbstractOperation<T>
7273
});
7374
return res;
7475
}
75-
}
76+
}

test/integration/connection-monitoring-and-pooling/connection.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ describe('Connection', function () {
144144
}
145145
}
146146
});
147+
148+
it('supports fire-and-forget messages', async function () {
149+
const options: ConnectionOptions = {
150+
...commonConnectOptions,
151+
connectionType: Connection,
152+
...this.configuration.options,
153+
metadata: makeClientMetadata({ driverInfo: {} }),
154+
extendedMetadata: addContainerMetadata(makeClientMetadata({ driverInfo: {} }))
155+
};
156+
157+
const conn = await connect(options);
158+
const readSpy = sinon.spy(conn, 'readMany');
159+
await conn.command(ns('$admin.cmd'), { ping: 1 }, { moreToCome: true });
160+
expect(readSpy).to.not.have.been.called;
161+
});
147162
});
148163

149164
describe('Connection - functional', function () {

test/integration/node-specific/mongo_client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ describe('class MongoClient', function () {
682682
expect(result2).to.have.property('ok', 1);
683683
});
684684

685-
it('sends endSessions with noResponse set', async () => {
685+
it('sends endSessions with writeConcern w = 0 set', async () => {
686686
const session = client.startSession(); // make a session to be ended
687687
await client.db('test').command({ ping: 1 }, { session });
688688
await session.endSession();
@@ -698,7 +698,7 @@ describe('class MongoClient', function () {
698698
expect(startedEvents).to.have.lengthOf(1);
699699
expect(startedEvents[0]).to.have.property('commandName', 'endSessions');
700700
expect(endEvents).to.have.lengthOf(1);
701-
expect(endEvents[0]).to.have.property('reply', undefined); // noReponse: true
701+
expect(endEvents[0]).to.containSubset({ reply: { ok: 1 } }); // writeConcern.w = 0
702702
});
703703

704704
context('when server selection would return no servers', () => {

test/unit/cmap/connection.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,6 @@ describe('new Connection()', function () {
2828

2929
before(() => mock.createServer().then(s => (server = s)));
3030

31-
it('supports fire-and-forget messages', async function () {
32-
server.setMessageHandler(request => {
33-
const doc = request.document;
34-
if (isHello(doc)) {
35-
request.reply(mock.HELLO);
36-
}
37-
38-
// black hole all other requests
39-
});
40-
41-
const options = {
42-
...connectionOptionsDefaults,
43-
connectionType: Connection,
44-
hostAddress: server.hostAddress(),
45-
authProviders: new MongoClientAuthProviders()
46-
};
47-
48-
const conn = await connect(options);
49-
const readSpy = sinon.spy(conn, 'readMany');
50-
await conn.command(ns('$admin.cmd'), { ping: 1 }, { noResponse: true });
51-
expect(readSpy).to.not.have.been.called;
52-
});
53-
5431
it('destroys streams which time out', async function () {
5532
server.setMessageHandler(request => {
5633
const doc = request.document;

0 commit comments

Comments
 (0)