Skip to content

Commit 5c2fa7d

Browse files
committed
test: add unit tests for causalConsistency setting
1 parent c875ac8 commit 5c2fa7d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/unit/sessions.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,46 @@ describe('Sessions - unit', function () {
167167
).to.throw('Properties "causalConsistency" and "snapshot" are mutually exclusive');
168168
});
169169

170+
it('should default `causalConsistency` to `true` for explicit non-snapshot sessions', function () {
171+
const session = new ClientSession(client, serverSessionPool, { explicit: true });
172+
expect(session.supports).property('causalConsistency', true);
173+
});
174+
175+
it('should respect `causalConsistency=false` option in explicit sessions', function () {
176+
const session = new ClientSession(client, serverSessionPool, {
177+
explicit: true,
178+
causalConsistency: false
179+
});
180+
expect(session.supports).property('causalConsistency', false);
181+
});
182+
183+
it('should respect `causalConsistency=true` option in explicit sessions', function () {
184+
const session = new ClientSession(client, serverSessionPool, {
185+
explicit: true,
186+
causalConsistency: true
187+
});
188+
expect(session.supports).property('causalConsistency', true);
189+
});
190+
191+
it('should default `causalConsistency` to `false` for implicit sessions', function () {
192+
const session = new ClientSession(client, serverSessionPool, { explicit: false });
193+
expect(session.supports).property('causalConsistency', false);
194+
});
195+
196+
it('should set `causalConsistency` to `false` in implicit sessions regardless of options', function () {
197+
const sessionTrue = new ClientSession(client, serverSessionPool, {
198+
explicit: false,
199+
causalConsistency: true
200+
});
201+
expect(sessionTrue.supports).property('causalConsistency', false);
202+
203+
const sessionFalse = new ClientSession(client, serverSessionPool, {
204+
explicit: false,
205+
causalConsistency: false
206+
});
207+
expect(sessionFalse.supports).property('causalConsistency', false);
208+
});
209+
170210
it('should default to `null` for `clusterTime`', function () {
171211
const session = new ClientSession(client, serverSessionPool);
172212
expect(session.clusterTime).to.not.exist;

0 commit comments

Comments
 (0)