-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(causalConsistency): adding an example test for causal consistency
Fixes NODE-1262
- Loading branch information
1 parent
9e7561a
commit 52cbc30
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
test/functional/operation_causal_consistency_example_tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); |