Skip to content

Commit 97ac778

Browse files
committed
test: fix
1 parent 55ecdc6 commit 97ac778

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed
Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { expect } from 'chai';
2+
13
import { CommandStartedEvent, Db, MongoClient } from '../../mongodb';
24

3-
describe('RunCommand API', () => {
5+
describe('class RunCommandCursor', () => {
46
let client: MongoClient;
57
let db: Db;
68
let commandsStarted: CommandStartedEvent[];
@@ -21,31 +23,31 @@ describe('RunCommand API', () => {
2123
await client.close();
2224
});
2325

24-
it('should not rerun init command', async () => {
26+
it('should only run init command once', async () => {
2527
const cursor = db.runCursorCommand({ find: 'collection', filter: {}, batchSize: 1 });
26-
cursor.batchSize = 1;
28+
cursor.setBatchSize(1);
2729
const it0 = cursor[Symbol.asyncIterator]();
2830
const it1 = cursor[Symbol.asyncIterator]();
2931

30-
const doc0_0 = await it0.next();
31-
const doc0_1 = await it1.next();
32-
const doc1_0 = await it0.next();
33-
const done = await it1.next();
34-
const done2 = await it0.next();
35-
const done3 = await it1.next();
32+
const next0it0 = await it0.next(); // find, 1 doc
33+
const next0it1 = await it1.next(); // getMore, 1 doc
3634

37-
// console.log(doc0_0, doc0_1, doc1_0, done, done2, done3);
38-
// console.log(commandsStarted);
39-
});
35+
expect(next0it0).to.deep.equal({ value: { _id: 0 }, done: false });
36+
expect(next0it1).to.deep.equal({ value: { _id: 1 }, done: false });
37+
expect(commandsStarted.map(c => c.commandName)).to.have.lengthOf(2);
38+
39+
const next1it0 = await it0.next(); // getMore, 1 doc
40+
const next1it1 = await it1.next(); // getMore, 0 doc & exhausted id
41+
42+
expect(next1it0).to.deep.equal({ value: { _id: 2 }, done: false });
43+
expect(next1it1).to.deep.equal({ value: undefined, done: true });
44+
expect(commandsStarted.map(c => c.commandName)).to.have.lengthOf(4);
45+
46+
const next2it0 = await it0.next();
47+
const next2it1 = await it1.next();
4048

41-
it('should be not strange', async () => {
42-
// const cursor = db.runCursorCommand({ find: 'collection', filter: {}, batchSize: 1 });
43-
// for await (const doc0 of cursor) {
44-
// for await (const doc1 of cursor) {
45-
// for await (const doc2 of cursor) {
46-
// console.log(doc0, doc1, doc2);
47-
// }
48-
// }
49-
// }
49+
expect(next2it0).to.deep.equal({ value: undefined, done: true });
50+
expect(next2it1).to.deep.equal({ value: undefined, done: true });
51+
expect(commandsStarted.map(c => c.commandName)).to.have.lengthOf(4);
5052
});
5153
});

0 commit comments

Comments
 (0)