Skip to content

Commit f21b49a

Browse files
committed
fix(NODE-3648): hook operation into cursor
1 parent 6dd5d5f commit f21b49a

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

src/cursor/abstract_cursor.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { ReadPreference, ReadPreferenceLike } from '../read_preference';
1414
import type { Server } from '../sdam/server';
1515
import type { Topology } from '../sdam/topology';
1616
import { Readable, Transform } from 'stream';
17-
import type { ExecutionResult } from '../operations/execute_operation';
17+
import { executeOperation, ExecutionResult } from '../operations/execute_operation';
18+
import { GetMoreOperation } from '../operations/get_more';
1819
import { ReadConcern, ReadConcernLike } from '../read_concern';
1920
import { TODO_NODE_3286, TypedEventEmitter } from '../mongo_types';
2021

@@ -610,16 +611,13 @@ export abstract class AbstractCursor<
610611
return;
611612
}
612613

613-
server.getMore(
614-
cursorNs,
615-
cursorId,
616-
{
617-
...this[kOptions],
618-
session: this[kSession],
619-
batchSize
620-
},
621-
callback
622-
);
614+
const getMoreOperation = new GetMoreOperation(cursorNs, cursorId, server, {
615+
...this[kOptions],
616+
session: this[kSession],
617+
batchSize
618+
});
619+
620+
executeOperation(this.topology, getMoreOperation, callback);
623621
}
624622
}
625623

src/operations/get_more.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,8 @@ export class GetMoreOperation extends AbstractOperation {
3737
* for execute passes a server so we will just use that one.
3838
*/
3939
execute(server: Server, session: ClientSession, callback: Callback<Document>): void {
40-
server.getMore(
41-
this.ns,
42-
this.cursorId,
43-
{
44-
...this.options,
45-
session: session
46-
},
47-
callback
48-
);
40+
server.getMore(this.ns, this.cursorId, this.options, callback);
4941
}
5042
}
5143

52-
defineAspects(GetMoreOperation, [Aspect.READ_OPERATION, Aspect.RETRYABLE, Aspect.CURSOR_ITERATING]);
44+
defineAspects(GetMoreOperation, [Aspect.READ_OPERATION, Aspect.CURSOR_ITERATING]);

test/functional/change_stream_spec.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ describe('Change Stream Spec - v1', function () {
6565
ctx.database = ctx.client.db(sDB);
6666
ctx.collection = ctx.database.collection(sColl);
6767
ctx.client.on('commandStarted', e => {
68+
console.log(e);
6869
if (e.commandName !== 'ismaster') _events.push(e);
6970
});
7071
});
@@ -170,6 +171,7 @@ describe('Change Stream Spec - v1', function () {
170171
const expectedEvents = test.expectations || [];
171172

172173
return function testAPM(ctx, events) {
174+
console.log('events', events);
173175
expectedEvents
174176
.map(e => e.command_started_event)
175177
.map(normalizeAPMEvent)

test/unit/operations/get_more.test.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ const { Long } = require('../../../src/bson');
66
const { GetMoreOperation } = require('../../../src/operations/get_more');
77
const { Server } = require('../../../src/sdam/server');
88
const { ClientSession } = require('../../../src/sessions');
9+
const { ReadPreference } = require('../../../src/read_preference');
910

1011
describe('GetMoreOperation', function () {
1112
const ns = 'db.coll';
1213
const cursorId = Long.fromNumber(1);
13-
const options = { batchSize: 100, comment: 'test', maxTimeMS: 500 };
14+
const options = {
15+
batchSize: 100,
16+
comment: 'test',
17+
maxTimeMS: 500,
18+
readPreference: ReadPreference.primary
19+
};
1420

1521
describe('#constructor', function () {
1622
const server = sinon.createStubInstance(Server, {});
@@ -39,15 +45,16 @@ describe('GetMoreOperation', function () {
3945
getMore: getMoreStub
4046
});
4147
const session = sinon.createStubInstance(ClientSession);
42-
const operation = new GetMoreOperation(ns, cursorId, server, options);
48+
const opts = { ...options, session };
49+
const operation = new GetMoreOperation(ns, cursorId, server, opts);
4350

4451
it('executes a getmore on the provided server', function (done) {
4552
const callback = () => {
4653
const call = getMoreStub.getCall(0);
4754
expect(getMoreStub.calledOnce).to.be.true;
4855
expect(call.args[0]).to.equal(ns);
4956
expect(call.args[1]).to.equal(cursorId);
50-
expect(call.args[2]).to.deep.equal({ ...options, session });
57+
expect(call.args[2]).to.deep.equal(opts);
5158
done();
5259
};
5360
operation.execute(server, session, callback);

0 commit comments

Comments
 (0)