Skip to content

Commit d38294b

Browse files
committed
test(causalConsistency): adding an example test for causal consistency
Fixes NODE-1262
1 parent 9e7561a commit d38294b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/functional/examples_tests.js

+40
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var assert = require('assert');
4+
const expect = require('chai').expect;
45
var co = require('co');
56
var test = require('./shared').assert;
67
var setupDatabase = require('./shared').setupDatabase;
@@ -1192,4 +1193,43 @@ describe('Examples', function() {
11921193
});
11931194
}
11941195
});
1196+
1197+
/**
1198+
* @ignore
1199+
*/
1200+
it('CausalConsistency', {
1201+
metadata: { requires: { topology: ['single'], mongodb: '>=3.6.0' } },
1202+
1203+
test: function(done) {
1204+
const configuration = this.configuration;
1205+
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
1206+
1207+
client.connect(function(err, client) {
1208+
const cleanup = e => {
1209+
client.close();
1210+
done(e);
1211+
};
1212+
1213+
if (err) return cleanup(err);
1214+
1215+
const db = client.db(configuration.db);
1216+
const collection = db.collection('causalConsistencyExample');
1217+
const session = client.startSession({ causalConsistency: true });
1218+
1219+
collection.insertOne({ darmok: 'jalad' }, { session });
1220+
collection.updateOne({ darmok: 'jalad' }, { $set: { darmok: 'tanagra' } }, { session });
1221+
1222+
collection.find({}, { session }).toArray(function(err, data) {
1223+
try {
1224+
expect(err).to.equal(null);
1225+
expect(data).to.exist;
1226+
} catch (e) {
1227+
return cleanup(e);
1228+
}
1229+
1230+
cleanup();
1231+
});
1232+
});
1233+
}
1234+
});
11951235
});

0 commit comments

Comments
 (0)