Skip to content

Commit cc2cb3f

Browse files
committed
last simple migration
1 parent b7bc9d4 commit cc2cb3f

1 file changed

Lines changed: 29 additions & 34 deletions

File tree

test/integration/crud/misc_cursors.test.js

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,54 +1180,49 @@ describe.only('Cursor', function () {
11801180
requires: { topology: ['single', 'replicaset', 'sharded'] }
11811181
},
11821182

1183-
test: function (done) {
1183+
test: async function () {
11841184
var i = 0,
11851185
docs = [{ b: 2 }, { b: 3 }],
11861186
doneCalled = 0;
11871187

11881188
const configuration = this.configuration;
1189-
client.connect((err, client) => {
1190-
expect(err).to.not.exist;
1191-
this.defer(() => client.close());
1189+
await client.connect();
11921190

1193-
const db = client.db(configuration.db);
1194-
db.createCollection(
1195-
'immediately_destroying_a_stream_prevents_the_query_from_executing',
1196-
(err, collection) => {
1197-
expect(err).to.not.exist;
1191+
const db = client.db(configuration.db);
1192+
const collection = await db.createCollection(
1193+
'immediately_destroying_a_stream_prevents_the_query_from_executing'
1194+
);
11981195

1199-
// insert all docs
1200-
collection.insertMany(docs, configuration.writeConcernMax(), err => {
1201-
expect(err).to.not.exist;
1196+
// insert all docs
1197+
await collection.insertMany(docs, configuration.writeConcernMax());
12021198

1203-
const cursor = collection.find();
1204-
const stream = cursor.stream();
1199+
const cursor = collection.find();
1200+
const stream = cursor.stream();
12051201

1206-
stream.on('data', function () {
1207-
i++;
1208-
});
1202+
stream.on('data', function () {
1203+
i++;
1204+
});
12091205

1210-
cursor.once('close', testDone('close'));
1211-
stream.once('error', testDone('error'));
1206+
cursor.once('close', testDone('close'));
1207+
stream.once('error', testDone('error'));
1208+
const promise = once(cursor, 'close');
12121209

1213-
stream.destroy();
1210+
stream.destroy();
12141211

1215-
function testDone() {
1216-
return err => {
1217-
++doneCalled;
1212+
function testDone() {
1213+
return err => {
1214+
++doneCalled;
12181215

1219-
if (doneCalled === 1) {
1220-
expect(err).to.not.exist;
1221-
test.strictEqual(0, i);
1222-
test.strictEqual(true, cursor.closed);
1223-
done();
1224-
}
1225-
};
1226-
}
1227-
});
1216+
if (doneCalled === 1) {
1217+
expect(err).to.not.exist;
1218+
test.strictEqual(0, i);
1219+
test.strictEqual(true, cursor.closed);
12281220
}
1229-
);
1230-
});
1221+
};
1222+
}
1223+
1224+
await cursor.close();
1225+
await promise;
12311226
}
12321227
});
12331228

0 commit comments

Comments
 (0)