From 6bbb8de0e92e9dae3bb75a85e9c122e4fb39287d Mon Sep 17 00:00:00 2001 From: Brett Ausmeier Date: Thu, 4 May 2017 13:26:03 +0200 Subject: [PATCH] Test passing readConcern option to connect Add a test for passing the readConcern option to the MongoClient connect method. The option should be passed through to the db. --- test/functional/readconcern_tests.js | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/functional/readconcern_tests.js b/test/functional/readconcern_tests.js index f0fe8ab373..b010a71294 100644 --- a/test/functional/readconcern_tests.js +++ b/test/functional/readconcern_tests.js @@ -236,6 +236,49 @@ exports['Should set majority readConcern using MongoClient'] = { } } +exports['Should set majority readConcern using MongoClient with options'] = { + metadata: { requires: { topology: 'replicaset', mongodb: ">= 3.1.7" } }, + + test: function(configuration, test) { + var MongoClient = configuration.require.MongoClient; + var listener = require('../..').instrument(function(err, instrumentations) {}); + // Contains all the apm events + var started = []; + var url = configuration.url(); + var options = { + readConcern: { + level: 'majority' + } + } + + // Connect using mongoclient + MongoClient.connect(url, options, function(err, db) { + test.equal(null, err); + test.deepEqual({level: 'majority'}, db.s.readConcern); + + // Get a collection + var collection = db.collection('readConcernCollection'); + // Validate readConcern + test.deepEqual({level: 'majority'}, collection.s.readConcern); + // Perform a find using the readConcern + listener.on('started', function(event) { + if(event.commandName == 'find') + started.push(event); + }); + + // Execute find + collection.find().toArray(function(err, r) { + test.equal(1, started.length); + test.deepEqual({level:'majority'}, started[0].command.readConcern); + + listener.uninstrument(); + db.close(); + test.done(); + }); + }); + } +} + exports['Should error out with readConcern level set to majority'] = { metadata: { requires: { topology: 'replicaset', mongodb: "<= 3.0.X" } },