Skip to content

Commit

Permalink
test(causalConsistency): adding an example test for causal consistency (
Browse files Browse the repository at this point in the history
  • Loading branch information
daprahamian authored Jan 30, 2018
1 parent 4c9b0f8 commit f2bb626
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/functional/examples_tests.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
});
});
}
});
});

0 comments on commit f2bb626

Please sign in to comment.