Skip to content

Commit 4bbdf20

Browse files
committed
feat(NODE-7441): use majority wc for ChangeStream.bufferedCount tests
1 parent ea4d84b commit 4bbdf20

1 file changed

Lines changed: 21 additions & 18 deletions

File tree

test/integration/change-streams/change_stream.test.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,14 +1184,14 @@ describe('Change Streams', function () {
11841184
{ requires: { topology: 'replicaset' } },
11851185
async function () {
11861186
// existing documents
1187-
await collection.insertOne({ a: 1 });
1188-
await collection.insertOne({ a: 2 });
1187+
await collection.insertOne({ a: 1 }, { writeConcern: { w: 'majority' } });
1188+
await collection.insertOne({ a: 2 }, { writeConcern: { w: 'majority' } });
11891189

11901190
changeStream = collection.watch([]);
11911191

11921192
// docs inserted after the change stream was created
1193-
await collection.insertOne({ a: 3 });
1194-
await collection.insertOne({ a: 4 });
1193+
await collection.insertOne({ a: 3 }, { writeConcern: { w: 'majority' } });
1194+
await collection.insertOne({ a: 4 }, { writeConcern: { w: 'majority' } });
11951195

11961196
expect(changeStream.bufferedCount()).to.equal(0);
11971197
await changeStream.close();
@@ -1203,8 +1203,8 @@ describe('Change Streams', function () {
12031203
async test() {
12041204
changeStream = collection.watch([]);
12051205
await initIteratorMode(changeStream);
1206-
await collection.insertOne({ a: 1 });
1207-
await collection.insertOne({ a: 2 });
1206+
await collection.insertOne({ a: 1 }, { writeConcern: { w: 'majority' } });
1207+
await collection.insertOne({ a: 2 }, { writeConcern: { w: 'majority' } });
12081208

12091209
expect(changeStream.bufferedCount()).to.equal(0);
12101210

@@ -1221,25 +1221,28 @@ describe('Change Streams', function () {
12211221
async test() {
12221222
changeStream = collection.watch([]);
12231223
await initIteratorMode(changeStream);
1224-
await collection.insertOne({ a: 1 });
1225-
await collection.insertOne({ a: 2 });
1224+
await collection.insertOne({ a: 1 }, { writeConcern: { w: 'majority' } });
1225+
await collection.insertOne({ a: 2 }, { writeConcern: { w: 'majority' } });
1226+
await collection.insertOne({ a: 3 }, { writeConcern: { w: 'majority' } });
12261227

12271228
expect(changeStream.bufferedCount()).to.equal(0);
1229+
12281230
// `next` triggers a batch fetch, buffering the documents
12291231
// and then consumes one document from that buffer
1230-
await changeStream.next();
1231-
expect(changeStream.bufferedCount()).to.equal(1);
1232-
await changeStream.next();
1233-
expect(changeStream.bufferedCount()).to.equal(0);
1232+
for (let i = 2; i >= 0; i--) {
1233+
await changeStream.next();
1234+
expect(changeStream.bufferedCount()).to.equal(i);
1235+
}
12341236

1235-
await collection.insertOne({ a: 1 });
1236-
await collection.insertOne({ a: 2 });
1237+
await collection.insertOne({ a: 1 }, { writeConcern: { w: 'majority' } });
1238+
await collection.insertOne({ a: 2 }, { writeConcern: { w: 'majority' } });
1239+
await collection.insertOne({ a: 3 }, { writeConcern: { w: 'majority' } });
12371240

12381241
// `tryNext` also triggers a batch fetch
1239-
await changeStream.tryNext();
1240-
expect(changeStream.bufferedCount()).to.equal(1);
1241-
await changeStream.tryNext();
1242-
expect(changeStream.bufferedCount()).to.equal(0);
1242+
for (let i = 2; i >= 0; i--) {
1243+
await changeStream.tryNext();
1244+
expect(changeStream.bufferedCount()).to.equal(i);
1245+
}
12431246
}
12441247
});
12451248
});

0 commit comments

Comments
 (0)