Skip to content

Commit f2bb626

Browse files
authored
test(causalConsistency): adding an example test for causal consistency (#1651)
Fixes NODE-1262
1 parent 4c9b0f8 commit f2bb626

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;
@@ -1224,4 +1225,43 @@ describe('Examples', function() {
12241225
});
12251226
}
12261227
});
1228+
1229+
/**
1230+
* @ignore
1231+
*/
1232+
it('CausalConsistency', {
1233+
metadata: { requires: { topology: ['single'], mongodb: '>=3.6.0' } },
1234+
1235+
test: function(done) {
1236+
const configuration = this.configuration;
1237+
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });
1238+
1239+
client.connect(function(err, client) {
1240+
const cleanup = e => {
1241+
client.close();
1242+
done(e);
1243+
};
1244+
1245+
if (err) return cleanup(err);
1246+
1247+
const db = client.db(configuration.db);
1248+
const collection = db.collection('causalConsistencyExample');
1249+
const session = client.startSession({ causalConsistency: true });
1250+
1251+
collection.insertOne({ darmok: 'jalad' }, { session });
1252+
collection.updateOne({ darmok: 'jalad' }, { $set: { darmok: 'tanagra' } }, { session });
1253+
1254+
collection.find({}, { session }).toArray(function(err, data) {
1255+
try {
1256+
expect(err).to.equal(null);
1257+
expect(data).to.exist;
1258+
} catch (e) {
1259+
return cleanup(e);
1260+
}
1261+
1262+
cleanup();
1263+
});
1264+
});
1265+
}
1266+
});
12271267
});

0 commit comments

Comments
 (0)