MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_topology_reset

Method test_topology_reset

test/test_fork.py:68–98  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

66 pass
67
68 def test_topology_reset(self):
69 # Tests that topologies are different from each other.
70 # Cannot use ID because virtual memory addresses may be the same.
71 # Cannot reinstantiate ObjectId in the topology settings.
72 # Relies on difference in PID when opened again.
73 parent_conn, child_conn = Pipe()
74 init_id = self.client._topology._pid
75 parent_cursor_exc = self.client._kill_cursors_executor
76
77 def target():
78 # Catch the fork warning and send to the parent for assertion.
79 with warnings.catch_warnings(record=True) as ctx:
80 warnings.simplefilter("always")
81 self.client.admin.command("ping")
82 child_conn.send(str(ctx[0]))
83 child_conn.send(self.client._topology._pid)
84 child_conn.send(
85 (
86 parent_cursor_exc != self.client._kill_cursors_executor,
87 "client._kill_cursors_executor was not reinitialized",
88 )
89 )
90
91 with self.fork(target):
92 self.assertEqual(self.client._topology._pid, init_id)
93 fork_warning = parent_conn.recv()
94 self.assertIn("MongoClient opened before fork", fork_warning)
95 child_id = parent_conn.recv()
96 self.assertNotEqual(child_id, init_id)
97 passed, msg = parent_conn.recv()
98 self.assertTrue(passed, msg)
99
100
101if __name__ == "__main__":

Callers

nothing calls this directly

Calls 2

recvMethod · 0.80
forkMethod · 0.45

Tested by

no test coverage detected