diff --git a/test/functional/examples_tests.js b/test/functional/examples_tests.js index 052ac6b0a0..75a034adc6 100644 --- a/test/functional/examples_tests.js +++ b/test/functional/examples_tests.js @@ -1,6 +1,7 @@ 'use strict'; var assert = require('assert'); +const expect = require('chai').expect; var co = require('co'); var test = require('./shared').assert; var setupDatabase = require('./shared').setupDatabase; @@ -1224,4 +1225,43 @@ describe('Examples', function() { }); } }); + + /** + * @ignore + */ + it('CausalConsistency', { + metadata: { requires: { topology: ['single'], mongodb: '>=3.6.0' } }, + + test: function(done) { + const configuration = this.configuration; + const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); + + client.connect(function(err, client) { + const cleanup = e => { + client.close(); + done(e); + }; + + if (err) return cleanup(err); + + const db = client.db(configuration.db); + const collection = db.collection('causalConsistencyExample'); + const session = client.startSession({ causalConsistency: true }); + + collection.insertOne({ darmok: 'jalad' }, { session }); + collection.updateOne({ darmok: 'jalad' }, { $set: { darmok: 'tanagra' } }, { session }); + + collection.find({}, { session }).toArray(function(err, data) { + try { + expect(err).to.equal(null); + expect(data).to.exist; + } catch (e) { + return cleanup(e); + } + + cleanup(); + }); + }); + } + }); });