Use ShardingTest to verify that CausalConsistency is supported by shell
- add negative tests verifying that causal consistency is enabled for the commands mentioned in
SERVER-28869// start a shard that could use read majority var st = new ShardingTest({shards:1, mongos:1, rs: {nodes:1, enableMajorityReadConcern: ""}} // once its started enable causal consistency db.setMongo().setCausalConsistency(); // check its enabled using assert.eq(db.getMongo().getCausalConsistency(), true) // check its enabled for a command (find, aggregate, count etc ) using db.getMongo().isCausalConsistencyEnabled(cmdName) {}
- add negative tests verifying that causal consistency is not enabled when its not explicitly set or for commands not in the list
- add tests that check that commands work as (using find as an example):
// make sure that operation time is not set assert.isnull(mongo.getOperationTime(), ...) // make sure that cluster time is not set assert.isnull(mongo.getClusterTime(), ...) db.runCommand({find:'foo'}) // make sure that operation time is still not set // make sure that cluster time is set db.runCommand({insert:'foo', documents:[{x: 1}]}) // now both cluster and operation time are set const time = mongo.getOperationTime() // increase operation time to one day ahead and run a command const time = mongo.setOperationTime(increasedTime) db.runCommand({find:'foo'}) // now it should fail with "Operation time can not be greater than cluster time" error // use the logical time returned as a new operation time and run the read // the result should match the write and returned operation time must be >= passed operation time