Skip to content

Commit 3545016

Browse files
committed
test(NODE-7204): address PR feedback
1 parent e052735 commit 3545016

1 file changed

Lines changed: 4 additions & 31 deletions

File tree

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

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect } from 'chai';
22

33
import { Binary, type Collection, type Db, type MongoClient } from '../../../src';
4+
import { sleep } from '../../tools/utils';
45

56
describe('Cursor Streams', function () {
67
let client: MongoClient;
@@ -13,7 +14,6 @@ describe('Cursor Streams', function () {
1314

1415
afterEach(async function () {
1516
await db.dropCollection('streaming_test').catch(() => null);
16-
await db.dropCollection('streaming_updates').catch(() => null);
1717
await client.close();
1818
});
1919

@@ -40,31 +40,11 @@ describe('Cursor Streams', function () {
4040
for await (const doc of cursor) {
4141
expect(doc).to.have.property('_id', docCount);
4242
docCount++;
43-
}
44-
45-
expect(docCount).to.equal(100);
46-
});
4743

48-
it('should handle pauses for async operations within the loop', async function () {
49-
const collection = db.collection<{ _id: number }>('streaming_test');
50-
const updateCollection = db.collection<{ _id: number; count: number }>('streaming_updates');
51-
await setupCollection(collection, 10);
52-
53-
const cursor = collection.find({}, { batchSize: 2 });
54-
let docCount = 0;
55-
56-
// The 'await' inside the loop naturally pauses the stream until the promise resolves.
57-
for await (const doc of cursor) {
58-
expect(doc).to.have.property('_id', docCount);
59-
docCount++;
60-
61-
// Perform an unrelated async operation
62-
await updateCollection.updateOne({ _id: 1 }, { $inc: { count: 1 } }, { upsert: true });
44+
await sleep(100);
6345
}
6446

65-
expect(docCount).to.equal(10);
66-
const finalUpdate = await updateCollection.findOne({ _id: 1 });
67-
expect(finalUpdate.count).to.equal(10);
47+
expect(docCount).to.equal(100);
6848
});
6949
});
7050

@@ -91,7 +71,6 @@ describe('Cursor Streams', function () {
9171

9272
it('should respect manual pause() and resume() calls', async function () {
9373
const collection = db.collection<{ _id: number }>('streaming_test');
94-
const updateCollection = db.collection<{ _id: number; count: number }>('streaming_updates');
9574
await setupCollection(collection, 10);
9675

9776
const stream = collection.find({}, { batchSize: 2 }).stream();
@@ -106,17 +85,11 @@ describe('Cursor Streams', function () {
10685
stream.pause();
10786

10887
// Perform an async operation, then resume
109-
updateCollection
110-
.updateOne({ _id: 1 }, { $inc: { count: 1 } }, { upsert: true })
111-
// Manually resume
112-
.then(() => stream.resume())
113-
.catch(reject);
88+
sleep(100).then(() => stream.resume());
11489
});
11590
});
11691

11792
expect(docCount).to.equal(10);
118-
const finalUpdate = await updateCollection.findOne({ _id: 1 });
119-
expect(finalUpdate.count).to.equal(10);
12093
});
12194
});
12295
});

0 commit comments

Comments
 (0)