From 329f65858424bd256595d5ade0b6560a0b291634 Mon Sep 17 00:00:00 2001 From: Bailey Pearson Date: Thu, 14 Mar 2024 15:17:29 -0600 Subject: [PATCH] misc test fixes --- .../collection-management/collection.test.ts | 18 ++---- test/integration/index_management.test.js | 61 ++++++------------- 2 files changed, 23 insertions(+), 56 deletions(-) diff --git a/test/integration/collection-management/collection.test.ts b/test/integration/collection-management/collection.test.ts index 5d645c46aa0..a4fa1d03677 100644 --- a/test/integration/collection-management/collection.test.ts +++ b/test/integration/collection-management/collection.test.ts @@ -389,20 +389,10 @@ describe('Collection', function () { ); }); - it('should support createIndex with no options', function (done) { - db.createCollection('create_index_without_options', {}, (err, collection) => { - collection.createIndex({ createdAt: 1 }, err => { - expect(err).to.not.exist; - - collection.indexInformation({ full: true }, (err, indexes) => { - expect(err).to.not.exist; - const indexNames = indexes.map(i => i.name); - expect(indexNames).to.include('createdAt_1'); - - done(); - }); - }); - }); + it('should support createIndex with no options', async function () { + const collection = await db.createCollection('create_index_without_options', {}); + await collection.createIndex({ createdAt: 1 }); + expect(await collection.indexExists('createdAt_1')).to.be.true; }); }); diff --git a/test/integration/index_management.test.js b/test/integration/index_management.test.js index 188452f11e0..1dd6fe6cc8e 100644 --- a/test/integration/index_management.test.js +++ b/test/integration/index_management.test.js @@ -459,48 +459,25 @@ describe('Indexes', function () { } }); - it('shouldCorrectlyCreateAndUseSparseIndex', { - metadata: { - requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } - }, - - test: function (done) { - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - var db = client.db(configuration.db); - db.createCollection('create_and_use_sparse_index_test', function (err) { - expect(err).to.not.exist; - const collection = db.collection('create_and_use_sparse_index_test'); - collection.createIndex( - { title: 1 }, - { sparse: true, writeConcern: { w: 1 } }, - function (err) { - expect(err).to.not.exist; - collection.insert( - [{ name: 'Jim' }, { name: 'Sarah', title: 'Princess' }], - configuration.writeConcernMax(), - function (err) { - expect(err).to.not.exist; - collection - .find({ title: { $ne: null } }) - .sort({ title: 1 }) - .toArray(function (err, items) { - test.equal(1, items.length); - test.equal('Sarah', items[0].name); - - // Fetch the info for the indexes - collection.indexInformation({ full: true }, function (err, indexInfo) { - expect(err).to.not.exist; - test.equal(2, indexInfo.length); - client.close(done); - }); - }); - } - ); - } - ); - }); - } + it('shouldCorrectlyCreateAndUseSparseIndex', async function () { + const db = client.db(this.configuration.db); + await db.createCollection('create_and_use_sparse_index_test'); + const collection = db.collection('create_and_use_sparse_index_test'); + await collection.createIndex({ title: 1 }, { sparse: true, writeConcern: { w: 1 } }); + await collection.insertMany( + [{ name: 'Jim' }, { name: 'Sarah', title: 'Princess' }], + this.configuration.writeConcernMax() + ); + const items = await collection + .find({ title: { $ne: null } }) + .sort({ title: 1 }) + .toArray(); + expect(items).to.have.lengthOf(1); + expect(items[0]).to.have.property('name', 'Sarah'); + + // Fetch the info for the indexes + const indexInfo = await collection.indexInformation({ full: true }); + expect(indexInfo).to.have.lengthOf(2); }); it('shouldCorrectlyHandleGeospatialIndexes', {