Skip to content

Commit 4c11661

Browse files
committed
test: make sure the getMore is started
1 parent 4add48c commit 4c11661

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

test/integration/crud/misc_cursors.test.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,36 +1848,44 @@ describe('Cursor', function () {
18481848
}
18491849
});
18501850

1851-
it('closes cursors when client is closed even if it has not been exhausted', async function () {
1852-
await client
1853-
.db()
1854-
.dropCollection('test_cleanup_tailable')
1855-
.catch(() => null);
1851+
it(
1852+
'closes cursors when client is closed even if it has not been exhausted',
1853+
{ requires: { topology: '!replicaset' } },
1854+
async function () {
1855+
await client
1856+
.db()
1857+
.dropCollection('test_cleanup_tailable')
1858+
.catch(() => null);
18561859

1857-
const collection = await client
1858-
.db()
1859-
.createCollection('test_cleanup_tailable', { capped: true, size: 1000, max: 3 });
1860+
const collection = await client
1861+
.db()
1862+
.createCollection('test_cleanup_tailable', { capped: true, size: 1000, max: 3 });
18601863

1861-
// insert only 2 docs in capped coll of 3
1862-
await collection.insertMany([{ a: 1 }, { a: 1 }]);
1864+
// insert only 2 docs in capped coll of 3
1865+
await collection.insertMany([{ a: 1 }, { a: 1 }]);
18631866

1864-
const cursor = collection.find({}, { tailable: true, awaitData: true, maxAwaitTimeMS: 2000 });
1867+
const cursor = collection.find({}, { tailable: true, awaitData: true, maxAwaitTimeMS: 2000 });
18651868

1866-
await cursor.next();
1867-
await cursor.next();
1868-
// will block for maxAwaitTimeMS (except we are closing the client)
1869-
const rejectedEarlyBecauseClientClosed = cursor.next().catch(error => error);
1869+
await cursor.next();
1870+
await cursor.next();
18701871

1871-
await client.close();
1872-
expect(cursor).to.have.property('closed', true);
1872+
const nextCommand = once(client, 'commandStarted');
1873+
// will block for maxAwaitTimeMS (except we are closing the client)
1874+
const rejectedEarlyBecauseClientClosed = cursor.next().catch(error => error);
1875+
1876+
for (
1877+
let [{ commandName }] = await nextCommand;
1878+
commandName !== 'getMore';
1879+
[{ commandName }] = await once(client, 'commandStarted')
1880+
);
18731881

1874-
const error = await rejectedEarlyBecauseClientClosed;
1875-
if (this.configuration.topologyType === 'LoadBalanced') {
1882+
await client.close();
1883+
expect(cursor).to.have.property('closed', true);
1884+
1885+
const error = await rejectedEarlyBecauseClientClosed;
18761886
expect(error).to.be.instanceOf(MongoClientClosedError);
1877-
} else {
1878-
expect(error).to.be.null;
18791887
}
1880-
});
1888+
);
18811889

18821890
it('shouldAwaitData', {
18831891
// Add a tag that our runner can trigger on

test/integration/node-specific/mongo_client.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
Db,
1313
getTopology,
1414
MongoClient,
15-
MongoClientClosedError,
1615
MongoNotConnectedError,
1716
MongoServerSelectionError,
1817
ReadPreference,

0 commit comments

Comments
 (0)