Skip to content

Commit 25a994c

Browse files
committed
add comments explaining the reason for this change and why the original test worked
1 parent 6282a0d commit 25a994c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

test/integration/sessions/sessions.prose.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,18 @@ describe('Sessions Prose Tests', () => {
107107
expect(allResults).to.have.lengthOf(operations.length);
108108
expect(events).to.have.lengthOf(operations.length);
109109

110+
// Previous version of this test was too strict: we were expecting that only one session be used for this scenario.
111+
// That was possible at the time because the operations were simple enough and the server fast enough that the operations would complete serially.
112+
//
113+
// However, with a more complex operation bulkWrite (like `Array.from({ length: 100_000 }).map(() => ({ insertOne: { document: { a: 1 } } })),`),
114+
// it's entirely possible and expected that bulkWrite would introduce a second session due to the time it takes to process all the inserts.
115+
//
116+
// The important bit of the test is that the number of sessions is less than the number of concurrent operations, so now instead of expecting exactly 1 session,
117+
// we just expect less than operations.length - 1 sessions.
118+
//
110119
const uniqueSessionIds = new Set(events.map(ev => ev.command.lsid.id.toString('hex')));
111-
expect(uniqueSessionIds).to.have.length.lessThanOrEqual(2);
120+
const expectedMaxSessions = operations.length - 1;
121+
expect(uniqueSessionIds).to.have.length.lessThan(expectedMaxSessions);
112122
});
113123
});
114124

0 commit comments

Comments
 (0)