summaryrefslogtreecommitdiff
path: root/src/mongo/idl/server_parameter_test_util.h
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-18 17:02:53 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-18 17:02:53 -0300
commit959575a5ca598bf5f37fb5cebe7ed1d80d3d71f7 (patch)
treeacc8d60aedb12b70048e676e8a7349deb0010db8 /src/mongo/idl/server_parameter_test_util.h
parent76588293975fc059cf076779e4283e6ffaf8afff (diff)
New upstream version 6.0.20upstream
Diffstat (limited to 'src/mongo/idl/server_parameter_test_util.h')
-rw-r--r--src/mongo/idl/server_parameter_test_util.h43
1 files changed, 32 insertions, 11 deletions
diff --git a/src/mongo/idl/server_parameter_test_util.h b/src/mongo/idl/server_parameter_test_util.h
index 566489dd1a9..f7e2ae31834 100644
--- a/src/mongo/idl/server_parameter_test_util.h
+++ b/src/mongo/idl/server_parameter_test_util.h
@@ -36,31 +36,28 @@
namespace mongo {
/**
- * Test-only RAII type that allows to set a server parameter value during the execution of a
- * unit test, or part of a unit test, and resets it to the original value on destruction.
+ * Test-only class that sets a server parameter to the specified value and allows
+ * resetting after the test completes.
*/
-class RAIIServerParameterControllerForTest {
+class ServerParameterControllerForTest {
public:
/**
* Constructor setting the server parameter to the specified value.
*/
template <typename T>
- RAIIServerParameterControllerForTest(const std::string& name, T value)
+ ServerParameterControllerForTest(const std::string& name, T value)
: _serverParam(ServerParameterSet::getNodeParameterSet()->get(name)) {
- // Save the old value
+ // Save the old value.
BSONObjBuilder bob;
_serverParam->appendSupportingRoundtrip(nullptr, bob, name);
_oldValue = bob.obj();
- // Set to the new value
+ // Set server param to the new value.
uassertStatusOK(_serverParam->set(BSON(name << value).firstElement()));
}
- /**
- * Destructor resetting the server parameter to the original value.
- */
- ~RAIIServerParameterControllerForTest() {
- // Reset to the old value
+ void reset() {
+ // Reset to the old value.
auto elem = _oldValue.firstElement();
uassertStatusOK(_serverParam->set(elem));
}
@@ -70,4 +67,28 @@ private:
BSONObj _oldValue;
};
+/**
+ * Test-only RAII type that wraps ServerParameterControllerForTest. Upon destruction, the server
+ * parameter will be set to its original value.
+ */
+class RAIIServerParameterControllerForTest {
+public:
+ /**
+ * Constructor setting the server parameter to the specified value.
+ */
+ template <typename T>
+ RAIIServerParameterControllerForTest(const std::string& name, T value)
+ : _serverParamController(ServerParameterControllerForTest(name, value)) {}
+
+ /**
+ * Destructor resetting the server parameter to the original value.
+ */
+ ~RAIIServerParameterControllerForTest() {
+ _serverParamController.reset();
+ }
+
+private:
+ ServerParameterControllerForTest _serverParamController;
+};
+
} // namespace mongo