File: 00002_delete_broken_tests.patch

package info (click to toggle)
pymongo 4.10.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,928 kB
  • sloc: python: 91,879; ansic: 4,537; javascript: 137; sh: 32; makefile: 31
file content (330 lines) | stat: -rw-r--r-- 12,640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
Description: Delete broken tests
Author: Salvo 'LtWorf' Tomaselli <ltworf@debian.org>
Forwarded: no
Last-Update: 2024-10-14

--- pymongo-4.10.1.orig/test/test_srv_polling.py
+++ pymongo-4.10.1/test/test_srv_polling.py
@@ -31,322 +31,3 @@ from pymongo.srv_resolver import _have_d
 from pymongo.synchronous.mongo_client import MongoClient
 
 WAIT_TIME = 0.1
-
-
-class SrvPollingKnobs:
-    def __init__(
-        self,
-        ttl_time=None,
-        min_srv_rescan_interval=None,
-        nodelist_callback=None,
-        count_resolver_calls=False,
-    ):
-        self.ttl_time = ttl_time
-        self.min_srv_rescan_interval = min_srv_rescan_interval
-        self.nodelist_callback = nodelist_callback
-        self.count_resolver_calls = count_resolver_calls
-
-        self.old_min_srv_rescan_interval = None
-        self.old_dns_resolver_response = None
-
-    def enable(self):
-        self.old_min_srv_rescan_interval = common.MIN_SRV_RESCAN_INTERVAL
-        self.old_dns_resolver_response = pymongo.srv_resolver._SrvResolver.get_hosts_and_min_ttl
-
-        if self.min_srv_rescan_interval is not None:
-            common.MIN_SRV_RESCAN_INTERVAL = self.min_srv_rescan_interval
-
-        def mock_get_hosts_and_min_ttl(resolver, *args):
-            assert self.old_dns_resolver_response is not None
-            nodes, ttl = self.old_dns_resolver_response(resolver)
-            if self.nodelist_callback is not None:
-                nodes = self.nodelist_callback()
-            if self.ttl_time is not None:
-                ttl = self.ttl_time
-            return nodes, ttl
-
-        patch_func: Any
-        if self.count_resolver_calls:
-            patch_func = FunctionCallRecorder(mock_get_hosts_and_min_ttl)
-        else:
-            patch_func = mock_get_hosts_and_min_ttl
-
-        pymongo.srv_resolver._SrvResolver.get_hosts_and_min_ttl = patch_func  # type: ignore
-
-    def __enter__(self):
-        self.enable()
-
-    def disable(self):
-        common.MIN_SRV_RESCAN_INTERVAL = self.old_min_srv_rescan_interval  # type: ignore
-        pymongo.srv_resolver._SrvResolver.get_hosts_and_min_ttl = (  # type: ignore
-            self.old_dns_resolver_response
-        )
-
-    def __exit__(self, exc_type, exc_val, exc_tb):
-        self.disable()
-
-
-class TestSrvPolling(PyMongoTestCase):
-    BASE_SRV_RESPONSE = [
-        ("localhost.test.build.10gen.cc", 27017),
-        ("localhost.test.build.10gen.cc", 27018),
-    ]
-
-    CONNECTION_STRING = "mongodb+srv://test1.test.build.10gen.cc"
-
-    def setUp(self):
-        # Patch timeouts to ensure short rescan SRV interval.
-        self.client_knobs = client_knobs(
-            heartbeat_frequency=WAIT_TIME,
-            min_heartbeat_interval=WAIT_TIME,
-            events_queue_frequency=WAIT_TIME,
-        )
-        self.client_knobs.enable()
-
-    def tearDown(self):
-        self.client_knobs.disable()
-
-    def get_nodelist(self, client):
-        return client._topology.description.server_descriptions().keys()
-
-    def assert_nodelist_change(self, expected_nodelist, client, timeout=(100 * WAIT_TIME)):
-        """Check if the client._topology eventually sees all nodes in the
-        expected_nodelist.
-        """
-
-        def predicate():
-            nodelist = self.get_nodelist(client)
-            if set(expected_nodelist) == set(nodelist):
-                return True
-            return False
-
-        wait_until(predicate, "see expected nodelist", timeout=timeout)
-
-    def assert_nodelist_nochange(self, expected_nodelist, client, timeout=(100 * WAIT_TIME)):
-        """Check if the client._topology ever deviates from seeing all nodes
-        in the expected_nodelist. Consistency is checked after sleeping for
-        (WAIT_TIME * 10) seconds. Also check that the resolver is called at
-        least once.
-        """
-
-        def predicate():
-            if set(expected_nodelist) == set(self.get_nodelist(client)):
-                return pymongo.srv_resolver._SrvResolver.get_hosts_and_min_ttl.call_count >= 1
-            return False
-
-        wait_until(predicate, "Node list equals expected nodelist", timeout=timeout)
-
-        nodelist = self.get_nodelist(client)
-        if set(expected_nodelist) != set(nodelist):
-            msg = "Client nodelist %s changed unexpectedly (expected %s)"
-            raise self.fail(msg % (nodelist, expected_nodelist))
-        self.assertGreaterEqual(
-            pymongo.srv_resolver._SrvResolver.get_hosts_and_min_ttl.call_count,  # type: ignore
-            1,
-            "resolver was never called",
-        )
-        return True
-
-    def run_scenario(self, dns_response, expect_change):
-        self.assertEqual(_have_dnspython(), True)
-        if callable(dns_response):
-            dns_resolver_response = dns_response
-        else:
-
-            def dns_resolver_response():
-                return dns_response
-
-        if expect_change:
-            assertion_method = self.assert_nodelist_change
-            count_resolver_calls = False
-            expected_response = dns_response
-        else:
-            assertion_method = self.assert_nodelist_nochange
-            count_resolver_calls = True
-            expected_response = self.BASE_SRV_RESPONSE
-
-        # Patch timeouts to ensure short test running times.
-        with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
-            client = self.simple_client(self.CONNECTION_STRING)
-            self.assert_nodelist_change(self.BASE_SRV_RESPONSE, client)
-            # Patch list of hosts returned by DNS query.
-            with SrvPollingKnobs(
-                nodelist_callback=dns_resolver_response, count_resolver_calls=count_resolver_calls
-            ):
-                assertion_method(expected_response, client)
-
-    def test_addition(self):
-        response = self.BASE_SRV_RESPONSE[:]
-        response.append(("localhost.test.build.10gen.cc", 27019))
-        self.run_scenario(response, True)
-
-    def test_removal(self):
-        response = self.BASE_SRV_RESPONSE[:]
-        response.remove(("localhost.test.build.10gen.cc", 27018))
-        self.run_scenario(response, True)
-
-    def test_replace_one(self):
-        response = self.BASE_SRV_RESPONSE[:]
-        response.remove(("localhost.test.build.10gen.cc", 27018))
-        response.append(("localhost.test.build.10gen.cc", 27019))
-        self.run_scenario(response, True)
-
-    def test_replace_both_with_one(self):
-        response = [("localhost.test.build.10gen.cc", 27019)]
-        self.run_scenario(response, True)
-
-    def test_replace_both_with_two(self):
-        response = [
-            ("localhost.test.build.10gen.cc", 27019),
-            ("localhost.test.build.10gen.cc", 27020),
-        ]
-        self.run_scenario(response, True)
-
-    def test_dns_failures(self):
-        from dns import exception
-
-        for exc in (exception.FormError, exception.TooBig, exception.Timeout):
-
-            def response_callback(*args):
-                raise exc("DNS Failure!")
-
-            self.run_scenario(response_callback, False)
-
-    def test_dns_record_lookup_empty(self):
-        response: list = []
-        self.run_scenario(response, False)
-
-    def _test_recover_from_initial(self, initial_callback):
-        # Construct a valid final response callback distinct from base.
-        response_final = self.BASE_SRV_RESPONSE[:]
-        response_final.pop()
-
-        def final_callback():
-            return response_final
-
-        with SrvPollingKnobs(
-            ttl_time=WAIT_TIME,
-            min_srv_rescan_interval=WAIT_TIME,
-            nodelist_callback=initial_callback,
-            count_resolver_calls=True,
-        ):
-            # Client uses unpatched method to get initial nodelist
-            client = self.simple_client(self.CONNECTION_STRING)
-            # Invalid DNS resolver response should not change nodelist.
-            self.assert_nodelist_nochange(self.BASE_SRV_RESPONSE, client)
-
-        with SrvPollingKnobs(
-            ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME, nodelist_callback=final_callback
-        ):
-            # Nodelist should reflect new valid DNS resolver response.
-            self.assert_nodelist_change(response_final, client)
-
-    def test_recover_from_initially_empty_seedlist(self):
-        def empty_seedlist():
-            return []
-
-        self._test_recover_from_initial(empty_seedlist)
-
-    def test_recover_from_initially_erroring_seedlist(self):
-        def erroring_seedlist():
-            raise ConfigurationError
-
-        self._test_recover_from_initial(erroring_seedlist)
-
-    def test_10_all_dns_selected(self):
-        response = [
-            ("localhost.test.build.10gen.cc", 27017),
-            ("localhost.test.build.10gen.cc", 27019),
-            ("localhost.test.build.10gen.cc", 27020),
-        ]
-
-        def nodelist_callback():
-            return response
-
-        with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
-            client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=0)
-            with SrvPollingKnobs(nodelist_callback=nodelist_callback):
-                self.assert_nodelist_change(response, client)
-
-    def test_11_all_dns_selected(self):
-        response = [
-            ("localhost.test.build.10gen.cc", 27019),
-            ("localhost.test.build.10gen.cc", 27020),
-        ]
-
-        def nodelist_callback():
-            return response
-
-        with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
-            client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=2)
-            with SrvPollingKnobs(nodelist_callback=nodelist_callback):
-                self.assert_nodelist_change(response, client)
-
-    def test_12_new_dns_randomly_selected(self):
-        response = [
-            ("localhost.test.build.10gen.cc", 27020),
-            ("localhost.test.build.10gen.cc", 27019),
-            ("localhost.test.build.10gen.cc", 27017),
-        ]
-
-        def nodelist_callback():
-            return response
-
-        with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
-            client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=2)
-            with SrvPollingKnobs(nodelist_callback=nodelist_callback):
-                sleep(2 * common.MIN_SRV_RESCAN_INTERVAL)
-                final_topology = set(client.topology_description.server_descriptions())
-                self.assertIn(("localhost.test.build.10gen.cc", 27017), final_topology)
-                self.assertEqual(len(final_topology), 2)
-
-    def test_does_not_flipflop(self):
-        with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
-            client = self.simple_client(self.CONNECTION_STRING, srvMaxHosts=1)
-            old = set(client.topology_description.server_descriptions())
-            sleep(4 * WAIT_TIME)
-            new = set(client.topology_description.server_descriptions())
-            self.assertSetEqual(old, new)
-
-    def test_srv_service_name(self):
-        # Construct a valid final response callback distinct from base.
-        response = [
-            ("localhost.test.build.10gen.cc.", 27019),
-            ("localhost.test.build.10gen.cc.", 27020),
-        ]
-
-        def nodelist_callback():
-            return response
-
-        with SrvPollingKnobs(ttl_time=WAIT_TIME, min_srv_rescan_interval=WAIT_TIME):
-            client = self.simple_client(
-                "mongodb+srv://test22.test.build.10gen.cc/?srvServiceName=customname"
-            )
-            with SrvPollingKnobs(nodelist_callback=nodelist_callback):
-                self.assert_nodelist_change(response, client)
-
-    def test_srv_waits_to_poll(self):
-        modified = [("localhost.test.build.10gen.cc", 27019)]
-
-        def resolver_response():
-            return modified
-
-        with SrvPollingKnobs(
-            ttl_time=WAIT_TIME,
-            min_srv_rescan_interval=WAIT_TIME,
-            nodelist_callback=resolver_response,
-        ):
-            client = self.simple_client(self.CONNECTION_STRING)
-            self.assertRaises(
-                AssertionError, self.assert_nodelist_change, modified, client, timeout=WAIT_TIME / 2
-            )
-
-    def test_import_dns_resolver(self):
-        # Regression test for PYTHON-4407
-        import dns.resolver
-
-        self.assertTrue(hasattr(dns.resolver, "resolve"))
-
-
-if __name__ == "__main__":
-    unittest.main()