Add unit and integration tests for monitoring module#281
Open
gimballock wants to merge 2 commits intostratum-mining:mainfrom
Open
Add unit and integration tests for monitoring module#281gimballock wants to merge 2 commits intostratum-mining:mainfrom
gimballock wants to merge 2 commits intostratum-mining:mainfrom
Conversation
eeb2a80 to
b72e8aa
Compare
Author
|
I added some additional tests, let me know if you see any areas that still need more coverage |
b72e8aa to
5a6886b
Compare
Member
|
PR title and description mention integration tests, but I don't see any on the diffs? |
5a6886b to
d97bd44
Compare
Cover the previously untested data-layer traits and HTTP API: - client.rs: Sv2ClientInfo accessors, to_metadata(), Sv2ClientsMonitoring default impls (get_sv2_client_by_id, get_sv2_clients_summary) - server.rs: ServerInfo accessors with Option<f32> hashrate handling, ServerMonitoring default impl (get_server_summary) - sv1.rs: Sv1ClientsMonitoring default impls (get_sv1_client_by_id, get_sv1_clients_summary including None-hashrate filtering) - prometheus_metrics.rs: conditional metric registration per role type, Prometheus text encoding round-trip - http_server.rs: Pagination unit tests (effective_limit clamping, paginate edge cases), HTTP endpoint integration tests using tower::oneshot against mock monitoring sources for all 9 API routes and /metrics Adds tower, http-body-util, hyper as dev-dependencies for the axum handler tests. Closes stratum-mining#161
3c6753e to
1c6f706
Compare
…ertions Add config setters (set_monitoring_address, set_monitoring_cache_refresh_secs) to PoolConfig, TranslatorConfig, and JobDeclaratorClientConfig so integration tests can enable the monitoring HTTP server on dynamic ports with a fast 1-second cache refresh interval. Create metrics_assert module with async helpers (fetch_metrics, fetch_api, assert_api_health, assert_uptime, assert_metric_gte, assert_metric_eq, assert_metric_present, assert_metric_not_present) that use spawn_blocking internally to avoid deadlocking the tokio current_thread runtime with synchronous minreq HTTP calls. Includes 11 unit tests for parsing/assertion logic. Add start_pool_with_monitoring, start_jdc_with_monitoring, and start_sv2_translator_with_monitoring test helpers that return JoinHandle and optional monitoring SocketAddr. Augment 9 existing integration test functions across 8 test files with metrics validation. Each test waits 2 seconds for the SnapshotCache to refresh, then validates topology-appropriate metrics: - Pool: sv2_clients_total, uptime, health endpoint, no sv2_server_channels - tProxy: sv2_server_channels, sv1_clients_total, server shares accepted - JDC: sv2_server_channels present, no sv2_clients_total Tests use #[tokio::test] (current_thread runtime) rather than multi_thread, because FallbackHandler::drop() panics if done() was never called -- aborting translator/JDC tasks on a multi_thread worker triggers a double-panic SIGABRT.
1c6f706 to
1a6ef0e
Compare
Author
|
Updated the integration tests to validate metric invariant related to their basic detecting ability: when connected channel counts should be non-zero, uptime should be positive, share count should be positive if we have seen a share, etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add test coverage for the monitoring/metrics system at both the unit and integration level.
Changes
Commit 1: Unit tests for monitoring data layer and HTTP API (1e45c73)
Unit tests for the previously untested monitoring module in stratum-apps/src/monitoring/:
Adds tower, http-body-util, hyper as dev-dependencies for the axum handler tests.
Commit 2: Integration test infrastructure and metrics assertions (1a6ef0e)
Config setters (pool/config.rs, translator/config.rs, jd-client/config.rs): Add set_monitoring_address() and set_monitoring_cache_refresh_secs() so tests can enable monitoring on dynamic ports with a fast 1-second cache refresh.
Test helpers (integration-tests/lib/mod.rs): Add start_pool_with_monitoring(), start_jdc_with_monitoring(), start_sv2_translator_with_monitoring() wrappers that configure monitoring and return the monitoring address.
Assertion helpers (integration-tests/lib/metrics_assert.rs): Async helpers (fetch_metrics, fetch_api, assert_api_health, assert_uptime, assert_metric_gte, assert_metric_eq, assert_metric_present, assert_metric_not_present) using spawn_blocking internally for the synchronous minreq HTTP calls. 11 unit tests for the parsing/assertion logic.
Metrics assertions augment 9 existing integration test functions across 8 test files. Each test waits 2 seconds for the SnapshotCache to refresh, then validates topology-appropriate metrics:
Technical notes
tokio::task::spawn_blockingto wrap synchronousminreqHTTP calls, preventing deadlocks on the single-threaded tokio test runtime#[tokio::test](current_thread) rather thanmulti_thread, becauseFallbackHandler::drop()infallback_coordinator.rspanics ifdone()was never called — aborting translator/JDC tasks on a multi_thread worker triggers a double-panic SIGABRT