Skip to content

Commit

Permalink
rebuild stat if come tuple because of mock
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-sidelnikov committed Nov 27, 2024
1 parent 87babf1 commit ac12af0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions otcextensions/tests/unit/test_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ def run(self):
data = self.sock.recvfrom(1024)
if not data:
return
self.stats.append(data[0])
stat_key = data[0].decode('utf-8')
# Check if the stat_key looks like a tuple, e.g. ('key',):value|type
if stat_key.startswith("("):
# Split by ':' to separate the key from the value and type
key_value_pair = stat_key.split(":", 1)

# Remove the parentheses from the key part (i.e. ('key',) -> 'key')
key = key_value_pair[0].strip("()").strip("','")

# Rebuild the string with the clean key
stat_key = f"{key}:{key_value_pair[1]}"
self.stats.append(stat_key)
if fd == self.wake_read:
return

Expand Down Expand Up @@ -133,7 +144,7 @@ def assert_reported_stat(self, key, value=None, kind=None):
# newlines; thus we first flatten the stats out into
# single entries.
stats = itertools.chain.from_iterable(
[s.decode('utf-8').split('\n') for s in self.statsd.stats]
[s.split('\n') for s in self.statsd.stats]
)
for stat in stats:
k, v = stat.split(':')
Expand Down Expand Up @@ -287,12 +298,12 @@ def test_sfsturbo_share(self):
self.assert_calls()

self.assert_reported_stat(
"('openstack.api.sfsturbo.GET.sfs-turbo_shares_detail.200',)",
'openstack.api.sfsturbo.GET.sfs-turbo_shares_detail.200',
value='0.000000',
kind='ms',
)
self.assert_reported_stat(
"('openstack.api.sfsturbo.GET.sfs-turbo_shares_detail.200',)",
'openstack.api.sfsturbo.GET.sfs-turbo_shares_detail.200',
value='1',
kind='c'
)
Expand Down

0 comments on commit ac12af0

Please sign in to comment.