From 71864eaf8acab7b95d53d18578c2a38ab8ff83f0 Mon Sep 17 00:00:00 2001 From: Ali Mir Date: Tue, 15 Jun 2021 21:02:54 +0000 Subject: SERVER-56605 Add testing for setting implicit default after a heartbeat reconfig (cherry picked from commit 686dad084a738a44c2a298a98a21bdb81f0fe683) --- ...at_reconfig_propagates_default_write_concern.js | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 jstests/replsets/heartbeat_reconfig_propagates_default_write_concern.js diff --git a/jstests/replsets/heartbeat_reconfig_propagates_default_write_concern.js b/jstests/replsets/heartbeat_reconfig_propagates_default_write_concern.js new file mode 100644 index 00000000000..4f713c100ca --- /dev/null +++ b/jstests/replsets/heartbeat_reconfig_propagates_default_write_concern.js @@ -0,0 +1,58 @@ +/* + * Test that a heartbeat reconfig propagated from the primary to a new secondary + * successfully sets the default write concern on the secondary. To do this, we start either a PSS + * or PSA replica set. We then add a fourth secondary to the replica set, and verify that it sets + * its implicit default write concern correctly. We don't test cases with cluster-wide write concern + * set, because then the secondary won't set its implicit default write concern from a heartbeat + * reconfig. + * @tags: [requires_fcv_50] + */ + +(function() { +'use strict'; + +load("jstests/replsets/rslib.js"); + +function runTest(hasArbiter) { + jsTestLog("Running test with hasArbiter: " + tojson(hasArbiter)); + + let replSetNodes = 3; + if (hasArbiter) { + replSetNodes = [{}, {}, {arbiter: true}]; + } + const rst = new ReplSetTest({ + nodes: replSetNodes, + }); + + rst.startSet(); + rst.initiate(); + const primary = rst.getPrimary(); + + const newSecondary = rst.add(); + assert.soon(() => isConfigCommitted(primary)); + const config = rst.getReplSetConfigFromNode(); + + config.members.push({_id: 3, host: newSecondary.host}); + config.version++; + + assert.commandWorked(primary.adminCommand({replSetReconfig: config})); + assert.soon(() => isConfigCommitted(primary)); + + rst.waitForConfigReplication(primary); + rst.awaitReplication(); + + let res = assert.commandWorked(newSecondary.adminCommand({getDefaultRWConcern: 1})); + // A PSS set will have a default write concern of {w: "majority"}. A PSA set will have a default + // write concern of {w: 1}. + if (hasArbiter) { + assert(!res.defaultWriteConcern, tojson(res)); + } else { + assert.eq(res.defaultWriteConcern, {w: "majority", wtimeout: 0}, tojson(res)); + } + assert.eq(res.defaultWriteConcernSource, "implicit", tojson(res)); + rst.stopSet(); +} + +runTest(false /* hasArbiter */); +runTest(true /* hasArbiter */); +})(); \ No newline at end of file -- cgit v1.2.1