Skip to content

Commit

Permalink
It: Include full path for admin stat it test failures (#453)
Browse files Browse the repository at this point in the history
* It: Include full path for admin stat it test failures

This patch makes it a little easier to debug the metric & operation that
causes an integration test for stats to fail.

Signed-off-by: Christopher Beard <[email protected]>

* Update src/integration-tests/test_admin_client.py

Co-authored-by: Evgeny Malygin <[email protected]>
Signed-off-by: Chris Beard <[email protected]>

---------

Signed-off-by: Christopher Beard <[email protected]>
Signed-off-by: Chris Beard <[email protected]>
Co-authored-by: Evgeny Malygin <[email protected]>
  • Loading branch information
chrisbeard and 678098 authored Oct 11, 2024
1 parent 01693b0 commit b7bd491
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/integration-tests/test_admin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def extract_stats(admin_response: str) -> dict:
def expect_same_structure(
entry: Union[dict, list, str, int],
expected: Union[dict, list, str, int, dt.ValueConstraint],
path: str = "",
) -> None:
"""
Check if the specified 'entry' has the same structure as the specified 'expected'.
Expand All @@ -100,14 +101,20 @@ def expect_same_structure(

if isinstance(expected, dict):
assert isinstance(entry, dict)
assert expected.keys() == entry.keys()
assert expected.keys() == entry.keys(), (
path,
"Extra expected keys:",
expected.keys() - entry.keys(),
"Missing expected keys:",
entry.keys() - expected.keys(),
)
for key in expected:
expect_same_structure(entry[key], expected[key])
expect_same_structure(entry[key], expected[key], path + "." + key)
elif isinstance(expected, list):
assert isinstance(entry, list)
assert len(expected) == len(entry)
for obj2, expected2 in zip(entry, expected):
expect_same_structure(obj2, expected2)
expect_same_structure(obj2, expected2, path + "." + key)
elif isinstance(expected, str):
assert isinstance(entry, str)
assert expected == entry
Expand All @@ -117,7 +124,7 @@ def expect_same_structure(
assert expected.check(entry)
else:
assert isinstance(expected, int)
assert entry == expected
assert entry == expected, (path, "expected:", expected, "actual:", entry)


def test_breathing(single_node: Cluster) -> None:
Expand Down Expand Up @@ -210,7 +217,7 @@ def test_queue_stats(single_node: Cluster) -> None:
stats = extract_stats(admin.send_admin("encoding json_pretty stat show"))
queue_stats = stats["domainQueues"]["domains"][tc.DOMAIN_FANOUT][task.uri]

expect_same_structure(queue_stats, dt.TEST_QUEUE_STATS_AFTER_POST)
expect_same_structure(queue_stats, dt.TEST_QUEUE_STATS_AFTER_POST, "after-post")

# Stage 2: check stats after confirming messages
consumer_foo: Client = proxy.create_client("consumer_foo")
Expand All @@ -228,7 +235,9 @@ def test_queue_stats(single_node: Cluster) -> None:
stats = extract_stats(admin.send_admin("encoding json_pretty stat show"))
queue_stats = stats["domainQueues"]["domains"][tc.DOMAIN_FANOUT][task.uri]

expect_same_structure(queue_stats, dt.TEST_QUEUE_STATS_AFTER_CONFIRM)
expect_same_structure(
queue_stats, dt.TEST_QUEUE_STATS_AFTER_CONFIRM, "after-confirm"
)

# Stage 3: check stats after purging an appId
res = admin.send_admin(
Expand All @@ -239,7 +248,7 @@ def test_queue_stats(single_node: Cluster) -> None:
stats = extract_stats(admin.send_admin("encoding json_pretty stat show"))
queue_stats = stats["domainQueues"]["domains"][tc.DOMAIN_FANOUT][task.uri]

expect_same_structure(queue_stats, dt.TEST_QUEUE_STATS_AFTER_PURGE)
expect_same_structure(queue_stats, dt.TEST_QUEUE_STATS_AFTER_PURGE, "after-purge")

consumer_foo.close(f"{task.uri}?id=foo")
consumer_bar.close(f"{task.uri}?id=bar")
Expand All @@ -251,7 +260,7 @@ def test_queue_stats(single_node: Cluster) -> None:
res = admin.send_admin("encoding json_pretty stat show")
obj = json.loads(res)

expect_same_structure(obj, dt.TEST_QUEUE_STATS_TOO_OFTEN_SNAPSHOTS)
expect_same_structure(obj, dt.TEST_QUEUE_STATS_TOO_OFTEN_SNAPSHOTS, "too-often")

admin.stop()

Expand Down

0 comments on commit b7bd491

Please sign in to comment.