Skip to content

Commit

Permalink
fix: remove existing session from cloned cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Mar 16, 2021
1 parent d4e297e commit 30ccd86
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cursor/aggregation_cursor.ts
Expand Up @@ -54,6 +54,7 @@ export class AggregationCursor extends AbstractCursor {

clone(): AggregationCursor {
const clonedOptions = mergeOptions({}, this[kOptions]);
delete clonedOptions.session;
return new AggregationCursor(this[kParent], this.topology, this.namespace, this[kPipeline], {
...clonedOptions
});
Expand Down
1 change: 1 addition & 0 deletions src/cursor/find_cursor.ts
Expand Up @@ -54,6 +54,7 @@ export class FindCursor extends AbstractCursor {

clone(): FindCursor {
const clonedOptions = mergeOptions({}, this[kBuiltOptions]);
delete clonedOptions.session;
return new FindCursor(this.topology, this.namespace, this[kFilter], {
...clonedOptions
});
Expand Down
62 changes: 62 additions & 0 deletions test/functional/cursor.test.js
Expand Up @@ -1730,6 +1730,68 @@ describe('Cursor', function () {
}
});

it('removes session wheen cloning a find cursor', function (done) {
const configuration = this.configuration;
const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect((err, client) => {
expect(err).to.not.exist;

const db = client.db(configuration.db);
db.createCollection('clone_find_cursor_session', (err, collection) => {
expect(err).to.not.exist;

collection.insertOne({ a: 1 }, configuration.writeConcernMax(), err => {
expect(err).to.not.exist;

const cursor = collection.find();
const clonedCursor = cursor.clone();
cursor.toArray(err => {
expect(err).to.not.exist;
clonedCursor.toArray(err => {
expect(err).to.not.exist;
client.close();
done();
});
});
});
});
});
});

it('removes session wheen cloning an aggregation cursor', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
},

test: function (done) {
const configuration = this.configuration;
const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
client.connect((err, client) => {
expect(err).to.not.exist;

const db = client.db(configuration.db);
db.createCollection('clone_aggregation_cursor_session', (err, collection) => {
expect(err).to.not.exist;

collection.insertOne({ a: 1 }, configuration.writeConcernMax(), err => {
expect(err).to.not.exist;

const cursor = collection.aggregate([{ $match: { a: 1 } }]);
const clonedCursor = cursor.clone();
cursor.toArray(err => {
expect(err).to.not.exist;
clonedCursor.toArray(err => {
expect(err).to.not.exist;
client.close();
done();
});
});
});
});
});
}
});

it('destroying a stream stops it', {
// Add a tag that our runner can trigger on
// in this case we are setting that node needs to be higher than 0.10.X to run
Expand Down

0 comments on commit 30ccd86

Please sign in to comment.