Skip to content

Commit 948410a

Browse files
committed
Remove unneeded _filter_servers and test
1 parent d4f558a commit 948410a

File tree

3 files changed

+0
-45
lines changed

3 files changed

+0
-45
lines changed

pymongo/asynchronous/topology.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ async def _select_server(
404404
operation_id,
405405
deprioritized_servers,
406406
)
407-
servers = _filter_servers(servers, deprioritized_servers)
408407
if len(servers) == 1:
409408
return servers[0]
410409
server1, server2 = random.sample(servers, 2)
@@ -1129,16 +1128,3 @@ def _is_stale_server_description(current_sd: ServerDescription, new_sd: ServerDe
11291128
if current_tv["processId"] != new_tv["processId"]:
11301129
return False
11311130
return current_tv["counter"] > new_tv["counter"]
1132-
1133-
1134-
def _filter_servers(
1135-
candidates: list[Server], deprioritized_servers: Optional[list[Server]] = None
1136-
) -> list[Server]:
1137-
"""Filter out deprioritized servers from a list of server candidates."""
1138-
if not deprioritized_servers:
1139-
return candidates
1140-
1141-
filtered = [server for server in candidates if server not in deprioritized_servers]
1142-
1143-
# If not possible to pick a prioritized server, return the original list
1144-
return filtered or candidates

pymongo/synchronous/topology.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ def _select_server(
404404
operation_id,
405405
deprioritized_servers,
406406
)
407-
servers = _filter_servers(servers, deprioritized_servers)
408407
if len(servers) == 1:
409408
return servers[0]
410409
server1, server2 = random.sample(servers, 2)
@@ -1127,16 +1126,3 @@ def _is_stale_server_description(current_sd: ServerDescription, new_sd: ServerDe
11271126
if current_tv["processId"] != new_tv["processId"]:
11281127
return False
11291128
return current_tv["counter"] > new_tv["counter"]
1130-
1131-
1132-
def _filter_servers(
1133-
candidates: list[Server], deprioritized_servers: Optional[list[Server]] = None
1134-
) -> list[Server]:
1135-
"""Filter out deprioritized servers from a list of server candidates."""
1136-
if not deprioritized_servers:
1137-
return candidates
1138-
1139-
filtered = [server for server in candidates if server not in deprioritized_servers]
1140-
1141-
# If not possible to pick a prioritized server, return the original list
1142-
return filtered or candidates

test/test_topology.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -733,23 +733,6 @@ def test_unexpected_load_balancer(self):
733733
self.assertNotIn(("a", 27017), t.description.server_descriptions())
734734
self.assertEqual(t.description.topology_type_name, "Unknown")
735735

736-
def test_filtered_server_selection(self):
737-
s1 = Server(ServerDescription(("localhost", 27017)), pool=object(), monitor=object()) # type: ignore[arg-type]
738-
s2 = Server(ServerDescription(("localhost2", 27017)), pool=object(), monitor=object()) # type: ignore[arg-type]
739-
servers = [s1, s2]
740-
741-
result = _filter_servers(servers, deprioritized_servers=[s2])
742-
self.assertEqual(result, [s1])
743-
744-
result = _filter_servers(servers, deprioritized_servers=[s1, s2])
745-
self.assertEqual(result, servers)
746-
747-
result = _filter_servers(servers, deprioritized_servers=[])
748-
self.assertEqual(result, servers)
749-
750-
result = _filter_servers(servers)
751-
self.assertEqual(result, servers)
752-
753736

754737
def wait_for_primary(topology):
755738
"""Wait for a Topology to discover a writable server.

0 commit comments

Comments
 (0)