Skip to content

Commit a46a919

Browse files
committed
where
1 parent aabd070 commit a46a919

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as sinon from 'sinon';
88
import {
99
type AbstractCursor,
1010
AggregationCursor,
11+
Code,
1112
type Collection,
1213
Connection,
1314
type Db,
@@ -562,6 +563,48 @@ describe('AbortSignal support', () => {
562563
});
563564
});
564565

566+
describe.only('cursor $where example', () => {
567+
beforeEach(async function () {
568+
const utilClient = this.configuration.newClient();
569+
try {
570+
const collection = utilClient.db('abortSignal').collection('support');
571+
await collection.drop({}).catch(() => null);
572+
await collection.insertMany([
573+
{ a: 1, ssn: '0000-00-0001' },
574+
{ a: 2, ssn: '0000-00-0002' },
575+
{ a: 3, ssn: '0000-00-0003' }
576+
]);
577+
} finally {
578+
await utilClient.close();
579+
}
580+
});
581+
582+
it('follows expected stream error handling', async () => {
583+
const controller = new AbortController();
584+
const { signal } = controller;
585+
const cursor = collection.find(
586+
{
587+
$where: function () {
588+
while (true);
589+
}
590+
},
591+
{ signal, batchSize: 1, serializeFunctions: true }
592+
);
593+
594+
client.on(
595+
'commandStarted',
596+
ev => ev.commandName === 'find' && sleep(2).then(() => controller.abort())
597+
);
598+
599+
const start = performance.now();
600+
const result = await cursor.toArray().catch(error => error);
601+
const end = performance.now();
602+
expect(end - start).to.be.lessThan(10);
603+
604+
expect(result).to.be.instanceOf(DOMException);
605+
});
606+
});
607+
565608
describe('when auto connecting and the signal aborts', () => {
566609
let client: MongoClient;
567610
let db: Db;

0 commit comments

Comments
 (0)