0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-21 20:49:10 +01:00
mongodb/jstests/replsets/rollback_time_limit_param.js
Moustafa Maher be39a8421f SERVER-95628 Make rawMongoProgramOutput more robust (#28204)
GitOrigin-RevId: 6b01ab93e5ba70a22cc816931cd464b6f2ddbd13
2024-10-22 22:40:58 +00:00

50 lines
2.1 KiB
JavaScript

/**
* Test that the 'rollbackTimeLimitSecs' server parameter can be set both on startup and at runtime,
* and that we only accept positive numbers as values for it. This number represents the maximum
* allowed timespan of the rollback period, which is calculated using the wall clock times of oplog
* entries.
*/
import {ReplSetTest} from "jstests/libs/replsettest.js";
const testName = "rollback_time_limit_param";
// Make sure that we reject non-positive values for this parameter set on startup.
let rstWithBadStartupOptions = new ReplSetTest(
{name: testName, nodes: 1, nodeOptions: {setParameter: "rollbackTimeLimitSecs=-50"}});
assert.throws(function() {
rstWithBadStartupOptions.startSet();
});
assert(rawMongoProgramOutput("Bad value for parameter").match("\"rollbackTimeLimitSecs\""),
"failed to reject bad value for parameter");
// Now initialize the same parameter correctly on startup.
let rst = new ReplSetTest(
{name: testName, nodes: 1, nodeOptions: {setParameter: "rollbackTimeLimitSecs=1000"}});
rst.startSet();
rst.initiate();
let primary = rst.getPrimary();
// Check that the value of 'rollbackTimeLimitSecs' was initialized correctly on startup.
let valueSetOnStartup =
assert.commandWorked(primary.adminCommand({getParameter: 1, rollbackTimeLimitSecs: 1}))
.rollbackTimeLimitSecs;
assert.eq(NumberLong(1000), valueSetOnStartup);
// Check that the value of 'rollbackTimeLimitSecs' was set correctly at runtime.
assert.commandWorked(primary.adminCommand({setParameter: 1, rollbackTimeLimitSecs: 2000}));
let valueSetAtRuntime =
assert.commandWorked(primary.adminCommand({getParameter: 1, rollbackTimeLimitSecs: 1}))
.rollbackTimeLimitSecs;
assert.eq(NumberLong(2000), valueSetAtRuntime);
// Make sure that we reject non-positive values for this parameter set at runtime.
assert.commandFailedWithCode(primary.adminCommand({setParameter: 1, rollbackTimeLimitSecs: -5}),
ErrorCodes.BadValue);
assert.commandFailedWithCode(primary.adminCommand({setParameter: 1, rollbackTimeLimitSecs: 0}),
ErrorCodes.BadValue);
rst.stopSet();