Skip to content

Commit ae03f39

Browse files
committed
fix: more consistent implementation
1 parent 5c2fa7d commit ae03f39

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/sessions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
169169
this[kServerSession] = this.explicit ? this.sessionPool.acquire() : null;
170170
this[kTxnNumberIncrement] = 0;
171171

172-
const canEnableCausalConsistency = this.explicit && options.snapshot !== true;
172+
const defaultCausalConsistencyValue = this.explicit && options.snapshot !== true;
173173
this.supports = {
174174
// if we can enable causal consistency, do so by default
175-
causalConsistency: canEnableCausalConsistency && options.causalConsistency !== false
175+
causalConsistency: options.causalConsistency ?? defaultCausalConsistencyValue
176176
};
177177

178178
this.clusterTime = options.initialClusterTime;

test/unit/sessions.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,20 @@ describe('Sessions - unit', function () {
193193
expect(session.supports).property('causalConsistency', false);
194194
});
195195

196-
it('should set `causalConsistency` to `false` in implicit sessions regardless of options', function () {
197-
const sessionTrue = new ClientSession(client, serverSessionPool, {
196+
it('should respect `causalConsistency=false` option in implicit sessions', function () {
197+
const session = new ClientSession(client, serverSessionPool, {
198198
explicit: false,
199-
causalConsistency: true
199+
causalConsistency: false
200200
});
201-
expect(sessionTrue.supports).property('causalConsistency', false);
201+
expect(session.supports).property('causalConsistency', false);
202+
});
202203

203-
const sessionFalse = new ClientSession(client, serverSessionPool, {
204+
it('should respect `causalConsistency=true` option in implicit sessions', function () {
205+
const session = new ClientSession(client, serverSessionPool, {
204206
explicit: false,
205-
causalConsistency: false
207+
causalConsistency: true
206208
});
207-
expect(sessionFalse.supports).property('causalConsistency', false);
209+
expect(session.supports).property('causalConsistency', true);
208210
});
209211

210212
it('should default to `null` for `clusterTime`', function () {

0 commit comments

Comments
 (0)