-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(causal-consistency): support
afterClusterTime
in readConcern
- Loading branch information
Showing
3 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use strict'; | ||
const MongoClient = require('../../..').MongoClient, | ||
Timestamp = require('bson').Timestamp, | ||
expect = require('chai').expect, | ||
mock = require('../../mock'); | ||
|
||
const test = {}; | ||
describe('Sessions', function() { | ||
describe('Collection', function() { | ||
afterEach(() => mock.cleanup()); | ||
beforeEach(() => { | ||
return mock.createServer().then(server => { | ||
test.server = server; | ||
}); | ||
}); | ||
|
||
it('should include `afterClusterTime` in read command with causal consistency', { | ||
metadata: { requires: { topology: 'single' } }, | ||
|
||
test: function() { | ||
let findCommand; | ||
let insertOperationTime = Timestamp.fromNumber(Date.now()); | ||
test.server.setMessageHandler(request => { | ||
const doc = request.document; | ||
if (doc.ismaster) { | ||
request.reply(mock.DEFAULT_ISMASTER_36); | ||
} else if (doc.insert) { | ||
request.reply({ ok: 1, operationTime: insertOperationTime }); | ||
} else if (doc.find) { | ||
findCommand = doc; | ||
request.reply({ ok: 1 }); | ||
} else if (doc.endSessions) { | ||
request.reply({ ok: 1 }); | ||
} | ||
}); | ||
|
||
return MongoClient.connect(`mongodb://${test.server.uri()}/test`).then(client => { | ||
const session = client.startSession({ causalConsistency: true }); | ||
const coll = client.db('foo').collection('bar'); | ||
|
||
return coll | ||
.insert({ a: 42 }, { session: session }) | ||
.then(() => | ||
coll.findOne({}, null, { session: session, readConcern: { level: 'majoroy' } }) | ||
) | ||
.then(() => { | ||
expect(findCommand.readConcern).to.have.keys(['level', 'afterClusterTime']); | ||
expect(findCommand.readConcern.afterClusterTime).to.eql(insertOperationTime); | ||
return client.close(); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); |