Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(causalConsistency): adding an example test for causal consistency #1651

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the rest of the file be updated to use expect or should this test use the same format as the rest of the tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be a bit much for just this PR, would make it harder to read. Agreed that we should eventually do this in the future though.

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();
});
});
}
});
});