Skip to content

Commit eaf1f62

Browse files
debug
1 parent d7426ce commit eaf1f62

File tree

1 file changed

+42
-63
lines changed

1 file changed

+42
-63
lines changed

test/integration/crud/find.test.js

Lines changed: 42 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -496,71 +496,50 @@ describe('Find', function () {
496496
}
497497
});
498498

499-
it('shouldCorrectlyPerformFindsWithHintTurnedOn', {
500-
metadata: {
501-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
502-
},
499+
for (let i = 0; i < 500; ++i) {
500+
it('shouldCorrectlyPerformFindsWithHintTurnedOn' + i, async function () {
501+
const configuration = this.configuration;
502+
client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
503+
await client.connect();
503504

504-
test: function (done) {
505-
var configuration = this.configuration;
506-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
507-
client.connect(function (err, client) {
508-
var db = client.db(configuration.db);
509-
db.createCollection('test_hint', function (err, collection) {
510-
collection.insert({ a: 1 }, configuration.writeConcernMax(), function (err) {
511-
expect(err).to.not.exist;
512-
db.createIndex(
513-
collection.collectionName,
514-
'a',
515-
configuration.writeConcernMax(),
516-
function (err) {
517-
expect(err).to.not.exist;
518-
collection.find({ a: 1 }, { hint: 'a' }).toArray(function (err) {
519-
test.ok(err != null);
505+
const db = client.db(configuration.db);
506+
const collection = await db.createCollection('test_hint');
520507

521-
collection.find({ a: 1 }, { hint: ['a'] }).toArray(function (err, items) {
522-
expect(err).to.not.exist;
523-
test.equal(1, items.length);
524-
525-
collection.find({ a: 1 }, { hint: { a: 1 } }).toArray(function (err, items) {
526-
test.equal(1, items.length);
527-
528-
// Modify hints
529-
collection.hint = 'a_1';
530-
test.equal('a_1', collection.hint);
531-
collection.find({ a: 1 }).toArray(function (err, items) {
532-
test.equal(1, items.length);
533-
534-
collection.hint = ['a'];
535-
test.equal(1, collection.hint['a']);
536-
collection.find({ a: 1 }).toArray(function (err, items) {
537-
test.equal(1, items.length);
538-
539-
collection.hint = { a: 1 };
540-
test.equal(1, collection.hint['a']);
541-
collection.find({ a: 1 }).toArray(function (err, items) {
542-
test.equal(1, items.length);
543-
544-
collection.hint = null;
545-
test.ok(collection.hint == null);
546-
collection.find({ a: 1 }).toArray(function (err, items) {
547-
test.equal(1, items.length);
548-
// Let's close the db
549-
client.close(done);
550-
});
551-
});
552-
});
553-
});
554-
});
555-
});
556-
});
557-
}
558-
);
559-
});
560-
});
561-
});
562-
}
563-
});
508+
await collection.insert({ a: 1 }, configuration.writeConcernMax());
509+
510+
await db.createIndex(collection.collectionName, 'a', configuration.writeConcernMax());
511+
512+
expect(
513+
await collection
514+
.find({ a: 1 }, { hint: 'a' })
515+
.toArray()
516+
.catch(e => e)
517+
).to.be.instanceOf(Error);
518+
519+
// Test with hint as array
520+
expect(await collection.find({ a: 1 }, { hint: ['a'] }).toArray()).to.have.lengthOf(1);
521+
522+
// Test with hint as object
523+
expect(await collection.find({ a: 1 }, { hint: { a: 1 } }).toArray()).to.have.lengthOf(1);
524+
525+
// Modify hints
526+
collection.hint = 'a_1';
527+
expect(collection.hint).to.equal('a_1');
528+
expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1);
529+
530+
collection.hint = ['a'];
531+
expect(collection.hint['a']).to.equal(1);
532+
expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1);
533+
534+
collection.hint = { a: 1 };
535+
expect(collection.hint['a']).to.equal(1);
536+
expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1);
537+
538+
collection.hint = null;
539+
expect(collection.hint).to.be.null;
540+
expect(await collection.find({ a: 1 }).toArray()).to.have.lengthOf(1);
541+
});
542+
}
564543

565544
it('shouldCorrectlyPerformFindByObjectId', {
566545
metadata: {

0 commit comments

Comments
 (0)