Skip to content

Commit 7220196

Browse files
committed
more migrations
1 parent 9fb6018 commit 7220196

1 file changed

Lines changed: 66 additions & 91 deletions

File tree

test/integration/crud/misc_cursors.test.js

Lines changed: 66 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ describe.only('Cursor', function () {
217217
const db = client.db(configuration.db);
218218
const collection = await db.createCollection('test_count.ext');
219219

220-
const count = await collection.find().count();
220+
await collection.find().count();
221221

222222
async function insert() {
223223
for (var i = 0; i < 10; i++) {
@@ -1440,33 +1440,24 @@ describe.only('Cursor', function () {
14401440
}
14411441
);
14421442

1443-
it('shouldAwaitDataWithDocumentsAvailable', function (done) {
1443+
it('shouldAwaitDataWithDocumentsAvailable', async function () {
14441444
// www.mongodb.com/docs/display/DOCS/Tailable+Cursors
14451445

14461446
const configuration = this.configuration;
14471447
const client = configuration.newClient({ maxPoolSize: 1 });
1448-
client.connect((err, client) => {
1449-
expect(err).to.not.exist;
1450-
this.defer(() => client.close());
1448+
await client.connect();
14511449

1452-
const db = client.db(configuration.db);
1453-
const options = { capped: true, size: 8 };
1454-
db.createCollection('should_await_data_no_docs', options, (err, collection) => {
1455-
expect(err).to.not.exist;
1450+
const db = client.db(configuration.db);
1451+
const options = { capped: true, size: 8 };
1452+
const collection = await db.createCollection('should_await_data_no_docs', options);
14561453

1457-
// Create cursor with awaitData, and timeout after the period specified
1458-
const cursor = collection.find({}, { tailable: true, awaitData: true });
1459-
this.defer(() => cursor.close());
1454+
// Create cursor with awaitData, and timeout after the period specified
1455+
const cursor = collection.find({}, { tailable: true, awaitData: true });
1456+
// this.defer(() => cursor.close());
14601457

1461-
cursor.forEach(
1462-
() => { },
1463-
err => {
1464-
expect(err).to.not.exist;
1465-
done();
1466-
}
1467-
);
1468-
});
1469-
});
1458+
await cursor.forEach(() => { });
1459+
await cursor.close();
1460+
await client.close();
14701461
});
14711462

14721463
context('awaiting data core tailable cursor test', () => {
@@ -1560,7 +1551,7 @@ describe.only('Cursor', function () {
15601551
requires: { topology: ['single', 'replicaset', 'sharded'] }
15611552
},
15621553

1563-
test: function (done) {
1554+
test: async function () {
15641555
var docs = [];
15651556
docs[0] = {
15661557
_keywords: [
@@ -1739,39 +1730,20 @@ describe.only('Cursor', function () {
17391730
};
17401731

17411732
const configuration = this.configuration;
1742-
client.connect((err, client) => {
1743-
expect(err).to.not.exist;
1744-
this.defer(() => client.close());
1745-
1746-
const db = client.db(configuration.db);
1747-
// Insert all the docs
1748-
var collection = db.collection('shouldCorrectExecuteExplainHonoringLimit');
1749-
collection.insert(docs, configuration.writeConcernMax(), err => {
1750-
expect(err).to.not.exist;
1733+
await client.connect();
17511734

1752-
collection.createIndex({ _keywords: 1 }, configuration.writeConcernMax(), err => {
1753-
expect(err).to.not.exist;
1735+
const db = client.db(configuration.db);
1736+
// Insert all the docs
1737+
var collection = db.collection('shouldCorrectExecuteExplainHonoringLimit');
1738+
await collection.insert(docs, configuration.writeConcernMax());
17541739

1755-
collection
1756-
.find({ _keywords: 'red' })
1757-
.limit(10)
1758-
.toArray(function (err, result) {
1759-
expect(err).to.not.exist;
1760-
test.ok(result != null);
1740+
await collection.createIndex({ _keywords: 1 }, configuration.writeConcernMax());
17611741

1762-
collection
1763-
.find({ _keywords: 'red' }, {})
1764-
.limit(10)
1765-
.explain(function (err, result) {
1766-
expect(err).to.not.exist;
1767-
test.ok(result != null);
1742+
let result = await collection.find({ _keywords: 'red' }).limit(10).toArray();
1743+
test.ok(result != null);
17681744

1769-
done();
1770-
});
1771-
});
1772-
});
1773-
});
1774-
});
1745+
result = await collection.find({ _keywords: 'red' }, {}).limit(10).explain();
1746+
test.ok(result != null);
17751747
}
17761748
});
17771749

@@ -2476,7 +2448,6 @@ describe.only('Cursor', function () {
24762448
metadata: { requires: { topology: ['single'], mongodb: '<7.0.0' } },
24772449

24782450
test: function (done) {
2479-
console.log(`pavel >>> test started`);
24802451
const configuration = this.configuration;
24812452
const client = configuration.newClient();
24822453
client.connect((err, client) => {
@@ -3035,54 +3006,57 @@ describe.only('Cursor', function () {
30353006
await client.close();
30363007
});
30373008

3038-
const testTransformStream = (config, _done) => {
3009+
const testTransformStream = async config => {
30393010
const client = config.client;
30403011
const configuration = config.configuration;
30413012
const collectionName = config.collectionName;
30423013
const transformFunc = config.transformFunc;
30433014
const expectedSet = config.expectedSet;
30443015

30453016
let cursor;
3046-
const done = err => cursor.close(err2 => client.close(err3 => _done(err || err2 || err3)));
3017+
const done = async err => {
3018+
await cursor.close();
3019+
await client.close();
3020+
if (err) {
3021+
throw err;
3022+
}
3023+
};
30473024

3048-
client.connect((err, client) => {
3049-
expect(err).to.not.exist;
3025+
await client.connect();
30503026

3051-
const db = client.db(configuration.db);
3052-
let collection;
3053-
const docs = [
3054-
{ _id: 0, a: { b: 1, c: 0 } },
3055-
{ _id: 1, a: { b: 1, c: 0 } },
3056-
{ _id: 2, a: { b: 1, c: 0 } }
3057-
];
3058-
const resultSet = new Set();
3059-
Promise.resolve()
3060-
.then(() => db.createCollection(collectionName))
3061-
.then(() => (collection = db.collection(collectionName)))
3062-
.then(() => collection.insertMany(docs))
3063-
.then(() => {
3064-
cursor = collection.find();
3065-
return cursor.stream().map(transformFunc ?? (doc => doc));
3066-
})
3067-
.then(stream => {
3068-
stream.on('data', function (doc) {
3069-
resultSet.add(doc);
3070-
});
3027+
const db = client.db(configuration.db);
3028+
const docs = [
3029+
{ _id: 0, a: { b: 1, c: 0 } },
3030+
{ _id: 1, a: { b: 1, c: 0 } },
3031+
{ _id: 2, a: { b: 1, c: 0 } }
3032+
];
3033+
const resultSet = new Set();
3034+
await db.createCollection(collectionName);
3035+
const collection = await db.collection(collectionName);
3036+
await collection.insertMany(docs);
3037+
cursor = await collection.find();
3038+
const stream = await cursor.stream().map(transformFunc ?? (doc => doc));
30713039

3072-
stream.once('end', function () {
3073-
expect(resultSet).to.deep.equal(expectedSet);
3074-
done();
3075-
});
3040+
stream.on('data', function (doc) {
3041+
resultSet.add(doc);
3042+
});
30763043

3077-
stream.once('error', e => {
3078-
done(e);
3079-
});
3080-
})
3081-
.catch(e => done(e));
3044+
stream.once('end', function () {
3045+
expect(resultSet).to.deep.equal(expectedSet);
3046+
done();
3047+
});
3048+
3049+
stream.once('error', e => {
3050+
done(e);
30823051
});
3052+
3053+
const promise = once(stream, 'end');
3054+
await promise;
3055+
await cursor.close();
3056+
await client.close();
30833057
};
30843058

3085-
it('stream should apply the supplied transformation function to each document in the stream', function (done) {
3059+
it('stream should apply the supplied transformation function to each document in the stream', async function () {
30863060
const configuration = this.configuration;
30873061
const client = configuration.newClient({ w: 1 }, { maxPoolSize: 1 });
30883062
const expectedDocs = [
@@ -3098,10 +3072,10 @@ describe.only('Cursor', function () {
30983072
expectedSet: new Set(expectedDocs)
30993073
};
31003074

3101-
testTransformStream(config, done);
3075+
await testTransformStream(config);
31023076
});
31033077

3104-
it('stream should return a stream of unmodified docs if no transform function applied', function (done) {
3078+
it('stream should return a stream of unmodified docs if no transform function applied', async function () {
31053079
const configuration = this.configuration;
31063080
const client = configuration.newClient({ w: 1 }, { maxPoolSize: 1 });
31073081
const expectedDocs = [
@@ -3117,7 +3091,7 @@ describe.only('Cursor', function () {
31173091
expectedSet: new Set(expectedDocs)
31183092
};
31193093

3120-
testTransformStream(config, done);
3094+
await testTransformStream(config);
31213095
});
31223096

31233097
it.skip('should apply parent read preference to count command', function (done) {
@@ -3162,8 +3136,9 @@ describe.only('Cursor', function () {
31623136

31633137
await client.connect();
31643138

3165-
const collection = client.db().collection('documents');
3166-
await collection.drop();
3139+
const collection = client.db(configuration.db).collection('documents');
3140+
const err = await collection.drop().catch(e => e);
3141+
expect(err).to.exist;
31673142

31683143
const docs = [{ a: 1 }, { a: 2 }, { a: 3 }];
31693144
await collection.insertMany(docs);

0 commit comments

Comments
 (0)