From eaf1f62b96cd831ff8da562c7cb431e445c29686 Mon Sep 17 00:00:00 2001 From: bailey Date: Tue, 10 Jun 2025 11:29:07 -0600 Subject: [PATCH 1/4] debug --- test/integration/crud/find.test.js | 105 ++++++++++++----------------- 1 file changed, 42 insertions(+), 63 deletions(-) diff --git a/test/integration/crud/find.test.js b/test/integration/crud/find.test.js index c16a13aa64..5ade8868b8 100644 --- a/test/integration/crud/find.test.js +++ b/test/integration/crud/find.test.js @@ -496,71 +496,50 @@ describe('Find', function () { } }); - it('shouldCorrectlyPerformFindsWithHintTurnedOn', { - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, + for (let i = 0; i < 500; ++i) { + it('shouldCorrectlyPerformFindsWithHintTurnedOn' + i, async function () { + const configuration = this.configuration; + client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); + await client.connect(); - test: function (done) { - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - client.connect(function (err, client) { - var db = client.db(configuration.db); - db.createCollection('test_hint', function (err, collection) { - collection.insert({ a: 1 }, configuration.writeConcernMax(), function (err) { - expect(err).to.not.exist; - db.createIndex( - collection.collectionName, - 'a', - configuration.writeConcernMax(), - function (err) { - expect(err).to.not.exist; - collection.find({ a: 1 }, { hint: 'a' }).toArray(function (err) { - test.ok(err != null); + const db = client.db(configuration.db); + const collection = await db.createCollection('test_hint'); - collection.find({ a: 1 }, { hint: ['a'] }).toArray(function (err, items) { - expect(err).to.not.exist; - test.equal(1, items.length); - - collection.find({ a: 1 }, { hint: { a: 1 } }).toArray(function (err, items) { - test.equal(1, items.length); - - // Modify hints - collection.hint = 'a_1'; - test.equal('a_1', collection.hint); - collection.find({ a: 1 }).toArray(function (err, items) { - test.equal(1, items.length); - - collection.hint = ['a']; - test.equal(1, collection.hint['a']); - collection.find({ a: 1 }).toArray(function (err, items) { - test.equal(1, items.length); - - collection.hint = { a: 1 }; - test.equal(1, collection.hint['a']); - collection.find({ a: 1 }).toArray(function (err, items) { - test.equal(1, items.length); - - collection.hint = null; - test.ok(collection.hint == null); - collection.find({ a: 1 }).toArray(function (err, items) { - test.equal(1, items.length); - // Let's close the db - client.close(done); - }); - }); - }); - }); - }); - }); - }); - } - ); - }); - }); - }); - } - }); + await collection.insert({ a: 1 }, configuration.writeConcernMax()); + + await db.createIndex(collection.collectionName, 'a', configuration.writeConcernMax()); + + expect( + await collection + .find({ a: 1 }, { hint: 'a' }) + .toArray() + .catch(e => e) + ).to.be.instanceOf(Error); + + // Test with hint as array + expect(await collection.find({ a: 1 }, { hint: ['a'] }).toArray()).to.have.lengthOf(1); + + // Test with hint as object + expect(await collection.find({ a: 1 }, { hint: { a: 1 } }).toArray()).to.have.lengthOf(1); + + // Modify hints + collection.hint = 'a_1'; + expect(collection.hint).to.equal('a_1'); + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + + collection.hint = ['a']; + expect(collection.hint['a']).to.equal(1); + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + + collection.hint = { a: 1 }; + expect(collection.hint['a']).to.equal(1); + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + + collection.hint = null; + expect(collection.hint).to.be.null; + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + }); + } it('shouldCorrectlyPerformFindByObjectId', { metadata: { From 2b49d3ed8aea4ac5f80fbbebaf961369f03d1484 Mon Sep 17 00:00:00 2001 From: bailey Date: Tue, 10 Jun 2025 13:31:19 -0600 Subject: [PATCH 2/4] asdf --- test/integration/crud/find.test.js | 67 +++++++++++++++--------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/test/integration/crud/find.test.js b/test/integration/crud/find.test.js index 5ade8868b8..7b09188a41 100644 --- a/test/integration/crud/find.test.js +++ b/test/integration/crud/find.test.js @@ -496,50 +496,49 @@ describe('Find', function () { } }); - for (let i = 0; i < 500; ++i) { - it('shouldCorrectlyPerformFindsWithHintTurnedOn' + i, async function () { - const configuration = this.configuration; - client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - await client.connect(); + it('shouldCorrectlyPerformFindsWithHintTurnedOn', async function () { + const configuration = this.configuration; + client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); + await client.connect(); - const db = client.db(configuration.db); - const collection = await db.createCollection('test_hint'); + const db = client.db(configuration.db); + const collection = await db.createCollection('test_hint'); - await collection.insert({ a: 1 }, configuration.writeConcernMax()); + await collection.deleteMany({}); + await collection.insert({ a: 1 }, configuration.writeConcernMax()); - await db.createIndex(collection.collectionName, 'a', configuration.writeConcernMax()); + await db.createIndex(collection.collectionName, 'a', configuration.writeConcernMax()); - expect( - await collection - .find({ a: 1 }, { hint: 'a' }) - .toArray() - .catch(e => e) - ).to.be.instanceOf(Error); + expect( + await collection + .find({ a: 1 }, { hint: 'a' }) + .toArray() + .catch(e => e) + ).to.be.instanceOf(Error); - // Test with hint as array - expect(await collection.find({ a: 1 }, { hint: ['a'] }).toArray()).to.have.lengthOf(1); + // Test with hint as array + expect(await collection.find({ a: 1 }, { hint: ['a'] }).toArray()).to.have.lengthOf(1); - // Test with hint as object - expect(await collection.find({ a: 1 }, { hint: { a: 1 } }).toArray()).to.have.lengthOf(1); + // Test with hint as object + expect(await collection.find({ a: 1 }, { hint: { a: 1 } }).toArray()).to.have.lengthOf(1); - // Modify hints - collection.hint = 'a_1'; - expect(collection.hint).to.equal('a_1'); - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + // Modify hints + collection.hint = 'a_1'; + expect(collection.hint).to.equal('a_1'); + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); - collection.hint = ['a']; - expect(collection.hint['a']).to.equal(1); - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + collection.hint = ['a']; + expect(collection.hint['a']).to.equal(1); + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); - collection.hint = { a: 1 }; - expect(collection.hint['a']).to.equal(1); - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + collection.hint = { a: 1 }; + expect(collection.hint['a']).to.equal(1); + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); - collection.hint = null; - expect(collection.hint).to.be.null; - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); - }); - } + collection.hint = null; + expect(collection.hint).to.be.undefined; + expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + }); it('shouldCorrectlyPerformFindByObjectId', { metadata: { From 68a26b6b3b630af89eabb0480fe5de75c97597f3 Mon Sep 17 00:00:00 2001 From: bailey Date: Tue, 10 Jun 2025 13:33:24 -0600 Subject: [PATCH 3/4] typing --- test/integration/crud/find.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/crud/find.test.js b/test/integration/crud/find.test.js index 7b09188a41..93319bebb4 100644 --- a/test/integration/crud/find.test.js +++ b/test/integration/crud/find.test.js @@ -6,6 +6,7 @@ const { setTimeout } = require('timers'); const { Code, ObjectId, Long, Binary, ReturnDocument, CursorResponse } = require('../../mongodb'); describe('Find', function () { + /** @type(import('../../mongodb').MongoClient */ let client; beforeEach(async function () { From 2fe8db4980ee8adfea745d80016e724bd5a368e2 Mon Sep 17 00:00:00 2001 From: bailey Date: Wed, 11 Jun 2025 11:41:35 -0600 Subject: [PATCH 4/4] clean up test a bit more --- test/integration/crud/find.test.js | 42 +++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/test/integration/crud/find.test.js b/test/integration/crud/find.test.js index 93319bebb4..bba192e21b 100644 --- a/test/integration/crud/find.test.js +++ b/test/integration/crud/find.test.js @@ -1,9 +1,17 @@ 'use strict'; -const { assert: test } = require('../shared'); +const { assert: test, filterForCommands } = require('../shared'); const { expect } = require('chai'); const sinon = require('sinon'); const { setTimeout } = require('timers'); -const { Code, ObjectId, Long, Binary, ReturnDocument, CursorResponse } = require('../../mongodb'); +const { + Code, + ObjectId, + Long, + Binary, + ReturnDocument, + CursorResponse, + MongoServerError +} = require('../../mongodb'); describe('Find', function () { /** @type(import('../../mongodb').MongoClient */ @@ -499,7 +507,13 @@ describe('Find', function () { it('shouldCorrectlyPerformFindsWithHintTurnedOn', async function () { const configuration = this.configuration; - client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); + client = configuration.newClient(configuration.writeConcernMax(), { + monitorCommands: true + }); + + const finds = []; + client.on('commandStarted', filterForCommands('find', finds)); + await client.connect(); const db = client.db(configuration.db); @@ -515,30 +529,16 @@ describe('Find', function () { .find({ a: 1 }, { hint: 'a' }) .toArray() .catch(e => e) - ).to.be.instanceOf(Error); + ).to.be.instanceOf(MongoServerError); + expect(finds[0].command.hint).to.equal('a'); // Test with hint as array expect(await collection.find({ a: 1 }, { hint: ['a'] }).toArray()).to.have.lengthOf(1); + expect(finds[1].command.hint).to.deep.equal({ a: 1 }); // Test with hint as object expect(await collection.find({ a: 1 }, { hint: { a: 1 } }).toArray()).to.have.lengthOf(1); - - // Modify hints - collection.hint = 'a_1'; - expect(collection.hint).to.equal('a_1'); - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); - - collection.hint = ['a']; - expect(collection.hint['a']).to.equal(1); - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); - - collection.hint = { a: 1 }; - expect(collection.hint['a']).to.equal(1); - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); - - collection.hint = null; - expect(collection.hint).to.be.undefined; - expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1); + expect(finds[2].command.hint).to.deep.equal({ a: 1 }); }); it('shouldCorrectlyPerformFindByObjectId', {