From 5247e869a698ed58fde54aa9d462c2b83f0eef0a Mon Sep 17 00:00:00 2001 From: Dan Aprahamian Date: Mon, 22 Jan 2018 15:56:33 -0500 Subject: [PATCH] test(causalConsistency): adding an example test for causal consistency Fixes NODE-1262 --- test/functional/examples_tests.js | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) 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(); + }); + }); + } + }); });