Skip to content

Commit

Permalink
fix: TOOLS-2656 exact node ID matches with another node ID with the s…
Browse files Browse the repository at this point in the history
…ame prefix
  • Loading branch information
Jesse Schmidt committed Dec 7, 2023
1 parent dd0d730 commit cd0920c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/live_cluster/client/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,12 @@ def get_node(self, node) -> list[Node]:
# Me must now look for exact matches.

# Can't use "if not in self.node_lookup" here because we need to check for
# exact matches. Unless using node id than this condition requires they provide ip:port.
if node in self.node_lookup.keys():
return self.node_lookup[node]
# exact matches. Unless using node id than this condition requires they provide
# ip:port.
try:
return [self.node_lookup.get_exact(node)]
except KeyError:
pass

node_matches = self.node_lookup[node]
match = None
Expand Down
6 changes: 6 additions & 0 deletions lib/utils/lookup_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def get(self, k) -> list[ValueType]:
keys = self.get_key(k)
return [self._kv[key] for key in keys]

def get_exact(self, k) -> ValueType:
if k in self._kv:
return self._kv[k]

raise KeyError("Unable to find key '%s'" % (k))

def remove(self, k):
keys = self.get_key(k)

Expand Down
14 changes: 14 additions & 0 deletions test/unit/live_cluster/client/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ async def test_get_node(self):
n = await self.get_info_mock("A0000000000000" + str(i), ip=ip, port=port)
cl.update_node(n)

n = await self.get_info_mock("A", ip="1.1.1.1", port=3000)
cl.update_node(n)
n = await self.get_info_mock("AB", ip="2.2.2.2", port=3000)
cl.update_node(n)

expected = [
"192.168.0.1:3000",
"192.168.0.1:3001",
Expand Down Expand Up @@ -277,6 +282,15 @@ async def test_get_node(self):

self.assertCountEqual(expected, actual)

expected = [
"1.1.1.1:3000",
]

actual = cl.get_node("A")
actual = map(lambda x: x.key, actual)

self.assertCountEqual(expected, actual)

async def test_get_nodes(self):
cl = await self.get_cluster_mock(3)

Expand Down

0 comments on commit cd0920c

Please sign in to comment.