-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathtest_registry.py
More file actions
74 lines (60 loc) · 2.28 KB
/
Copy pathtest_registry.py
File metadata and controls
74 lines (60 loc) · 2.28 KB
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
"""Tests for the Prometheus metrics registry."""
from __future__ import annotations
from collections.abc import Iterator
import pytest
from prometheus_client import CollectorRegistry
from lean_spec.subspecs.metrics.registry import (
ATTESTATION_AGGREGATE_COVERAGE_DIFF_DIRECTIONS,
ATTESTATION_AGGREGATE_COVERAGE_SECTIONS,
BLOCK_PROPOSAL_ATTESTATION_BUILD_PHASES,
registry,
)
@pytest.fixture(autouse=True)
def _reset_registry() -> Iterator[None]:
"""Ensure metrics are uninitialized before and after each test."""
registry.reset()
registry._initialized = False
yield
registry.reset()
registry._initialized = False
def test_attestation_aggregate_coverage_metrics_registered() -> None:
"""Coverage gauges are created with default combined-subnet series."""
test_reg = CollectorRegistry()
registry.init(registry=test_reg)
for section in ATTESTATION_AGGREGATE_COVERAGE_SECTIONS:
assert (
test_reg.get_sample_value(
"lean_attestation_aggregate_coverage_validators",
{"section": section, "subnet": "combined"},
)
== 0.0
)
assert (
test_reg.get_sample_value(
"lean_attestation_aggregate_coverage_subnets",
{"section": section},
)
== 0.0
)
for direction in ATTESTATION_AGGREGATE_COVERAGE_DIFF_DIRECTIONS:
assert (
test_reg.get_sample_value(
"lean_attestation_aggregate_coverage_diff_validators",
{"direction": direction},
)
== 0.0
)
def test_block_proposal_attestation_build_metrics_registered() -> None:
"""Block-proposal attestation selection metrics are registered on init."""
test_reg = CollectorRegistry()
registry.init(registry=test_reg)
for phase in BLOCK_PROPOSAL_ATTESTATION_BUILD_PHASES:
assert (
test_reg.get_sample_value(
"lean_block_proposal_attestation_build_phase_seconds_count",
{"phase": phase},
)
is None
)
assert test_reg.get_sample_value("lean_block_proposal_attestation_builds_total") == 0.0
assert test_reg.get_sample_value("lean_block_proposal_child_payloads_consumed_total") == 0.0