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
Fixes NODE-1262
  • Loading branch information
daprahamian committed Jan 22, 2018
1 parent 9e7561a commit 52cbc30
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/functional/operation_causal_consistency_example_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
const setupDatabase = require('./shared').setupDatabase;
const expect = require('chai').expect;

describe('Causal Consistency Example', function() {
before(function() {
return setupDatabase(this.configuration);
});

it('does causal consistency', {
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 52cbc30

Please sign in to comment.