Skip to content

Commit

Permalink
fix: more consistent implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dariakp committed Nov 30, 2022
1 parent 5c2fa7d commit ae03f39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/sessions.ts
Expand Up @@ -169,10 +169,10 @@ export class ClientSession extends TypedEventEmitter<ClientSessionEvents> {
this[kServerSession] = this.explicit ? this.sessionPool.acquire() : null;
this[kTxnNumberIncrement] = 0;

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

this.clusterTime = options.initialClusterTime;
Expand Down
16 changes: 9 additions & 7 deletions test/unit/sessions.test.js
Expand Up @@ -193,18 +193,20 @@ describe('Sessions - unit', function () {
expect(session.supports).property('causalConsistency', false);
});

it('should set `causalConsistency` to `false` in implicit sessions regardless of options', function () {
const sessionTrue = new ClientSession(client, serverSessionPool, {
it('should respect `causalConsistency=false` option in implicit sessions', function () {
const session = new ClientSession(client, serverSessionPool, {
explicit: false,
causalConsistency: true
causalConsistency: false
});
expect(sessionTrue.supports).property('causalConsistency', false);
expect(session.supports).property('causalConsistency', false);
});

const sessionFalse = new ClientSession(client, serverSessionPool, {
it('should respect `causalConsistency=true` option in implicit sessions', function () {
const session = new ClientSession(client, serverSessionPool, {
explicit: false,
causalConsistency: false
causalConsistency: true
});
expect(sessionFalse.supports).property('causalConsistency', false);
expect(session.supports).property('causalConsistency', true);
});

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

0 comments on commit ae03f39

Please sign in to comment.