MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / mock_hello

Method mock_hello

test/asynchronous/pymongo_mocks.py:186–247  ·  view source on GitHub ↗

Return mock hello response (a dict) and round trip time.

(self, host)

Source from the content-addressed store, hash-verified

184 self.mock_max_write_batch_sizes[host] = size
185
186 def mock_hello(self, host):
187 """Return mock hello response (a dict) and round trip time."""
188 if host in self.mock_wire_versions:
189 min_wire_version, max_wire_version = self.mock_wire_versions[host]
190 else:
191 min_wire_version = common.MIN_SUPPORTED_WIRE_VERSION
192 max_wire_version = common.MAX_SUPPORTED_WIRE_VERSION
193
194 max_write_batch_size = self.mock_max_write_batch_sizes.get(
195 host, common.MAX_WRITE_BATCH_SIZE
196 )
197
198 rtt = self.mock_rtts.get(host, 0)
199
200 # host is like 'a:1'.
201 if host in self.mock_down_hosts:
202 raise NetworkTimeout("mock timeout")
203
204 elif host in self.mock_standalones:
205 response = {
206 "ok": 1,
207 HelloCompat.LEGACY_CMD: True,
208 "minWireVersion": min_wire_version,
209 "maxWireVersion": max_wire_version,
210 "maxWriteBatchSize": max_write_batch_size,
211 }
212 elif host in self.mock_members:
213 primary = host == self.mock_primary
214
215 # Simulate a replica set member.
216 response = {
217 "ok": 1,
218 HelloCompat.LEGACY_CMD: primary,
219 "secondary": not primary,
220 "setName": "rs",
221 "hosts": self.mock_hello_hosts,
222 "minWireVersion": min_wire_version,
223 "maxWireVersion": max_wire_version,
224 "maxWriteBatchSize": max_write_batch_size,
225 }
226
227 if self.mock_primary:
228 response["primary"] = self.mock_primary
229
230 if host in self.mock_arbiters:
231 response["arbiterOnly"] = True
232 response["secondary"] = False
233 elif host in self.mock_mongoses:
234 response = {
235 "ok": 1,
236 HelloCompat.LEGACY_CMD: True,
237 "minWireVersion": min_wire_version,
238 "maxWireVersion": max_wire_version,
239 "msg": "isdbgrid",
240 "maxWriteBatchSize": max_write_batch_size,
241 }
242 else:
243 # In test_internal_ips(), we try to connect to a host listed

Callers 1

_check_onceMethod · 0.45

Calls 3

NetworkTimeoutClass · 0.90
AutoReconnectClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected