summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/mock
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /src/mongo/dbtests/mock
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'src/mongo/dbtests/mock')
-rw-r--r--src/mongo/dbtests/mock/mock_replica_set.cpp16
-rw-r--r--src/mongo/dbtests/mock/mock_replica_set.h16
2 files changed, 18 insertions, 14 deletions
diff --git a/src/mongo/dbtests/mock/mock_replica_set.cpp b/src/mongo/dbtests/mock/mock_replica_set.cpp
index 3871e1ef191..b03ffd477ed 100644
--- a/src/mongo/dbtests/mock/mock_replica_set.cpp
+++ b/src/mongo/dbtests/mock/mock_replica_set.cpp
@@ -149,7 +149,7 @@ void MockReplicaSet::setPrimary(const string& hostAndPort) {
_primaryHost = hostAndPort;
- mockHelloCmd();
+ mockIsMasterCmd();
mockReplSetGetStatusCmd();
}
@@ -183,7 +183,7 @@ repl::ReplSetConfig MockReplicaSet::getReplConfig() const {
void MockReplicaSet::setConfig(const repl::ReplSetConfig& newConfig) {
_replConfig = newConfig;
- mockHelloCmd();
+ mockIsMasterCmd();
mockReplSetGetStatusCmd();
}
@@ -211,14 +211,14 @@ BSONObj MockReplicaSet::mockHelloResponseFor(const MockRemoteDBServer& server) c
const MemberConfig* member = _replConfig.findMemberByHostAndPort(hostAndPort);
if (!member) {
- builder.append("isWritablePrimary", false);
+ builder.append("ismaster", false);
builder.append("secondary", false);
vector<string> hostList;
builder.append("hosts", hostList);
} else {
const bool isPrimary = hostAndPort.toString() == getPrimary();
- builder.append("isWritablePrimary", isPrimary);
+ builder.append("ismaster", isPrimary);
builder.append("secondary", !isPrimary);
{
@@ -285,12 +285,14 @@ BSONObj MockReplicaSet::mockHelloResponseFor(const MockRemoteDBServer& server) c
return builder.obj();
}
-void MockReplicaSet::mockHelloCmd() {
+void MockReplicaSet::mockIsMasterCmd() {
for (ReplNodeMap::iterator nodeIter = _nodeMap.begin(); nodeIter != _nodeMap.end();
++nodeIter) {
- auto helloReply = mockHelloResponseFor(*nodeIter->second);
+ auto isMaster = mockHelloResponseFor(*nodeIter->second);
- nodeIter->second->setCommandReply("hello", helloReply);
+ // DBClientBase::isMaster() sends "ismaster", but ReplicaSetMonitor sends "isMaster".
+ nodeIter->second->setCommandReply("ismaster", isMaster);
+ nodeIter->second->setCommandReply("isMaster", isMaster);
}
}
diff --git a/src/mongo/dbtests/mock/mock_replica_set.h b/src/mongo/dbtests/mock/mock_replica_set.h
index d93ba956ee8..677d0b822a1 100644
--- a/src/mongo/dbtests/mock/mock_replica_set.h
+++ b/src/mongo/dbtests/mock/mock_replica_set.h
@@ -57,7 +57,7 @@ class ClockSource;
class MockReplicaSet {
public:
/**
- * Creates a mock replica set and automatically mocks the hello and replSetGetStatus commands
+ * Creates a mock replica set and automatically mocks the isMaster and replSetGetStatus commands
* based on the default replica set configuration. Either the first node is primary and the
* others are secondaries, or all are secondaries. By default, hostnames begin with "$", which
* signals to ReplicaSetMonitor and to ConnectionString::connect that these are mocked hosts.
@@ -87,11 +87,12 @@ public:
std::vector<std::string> getSecondaries() const;
/**
- * Sets the configuration for this replica sets. This also has a side effect of mocking the
- * hello and replSetGetStatus command responses based on the new config.
+ * Sets the configuration for this replica sets. This also has a side effect
+ * of mocking the ismaster and replSetGetStatus command responses based on
+ * the new config.
*
- * Note: does not automatically select a new primary. Can be done manually by calling
- * setPrimary.
+ * Note: does not automatically select a new primary. Can be done manually by
+ * calling setPrimary.
*/
void setConfig(const repl::ReplSetConfig& newConfig);
@@ -137,9 +138,10 @@ private:
typedef std::map<std::string, MockRemoteDBServer*> ReplNodeMap;
/**
- * Mocks the "hello" command based on the information on the current replica set configuration.
+ * Mocks the ismaster command based on the information on the current
+ * replica set configuration.
*/
- void mockHelloCmd();
+ void mockIsMasterCmd();
/**
* Mock the hello response for the given server.