From 0e5079f197e2528417c8a454499ec2bc1400b9e3 Mon Sep 17 00:00:00 2001 From: jbesraa Date: Fri, 31 Jan 2025 18:10:32 +0200 Subject: [PATCH] Add `tracing-subscriber` to testing This should allow us to examine the logs from the roles that are using `tracing` crate for logging. As a default only ERROR logs will be shown, in order to examine a different level of logging, `RUST_LOG` env variable should be modified. For example `RUST_LOG=info cargo test --test '*'` --- roles/Cargo.lock | 67 +++++++++++++++++++ roles/tests-integration/Cargo.toml | 1 + .../tests/pool_integration.rs | 4 ++ .../tests/sniffer_integration.rs | 4 ++ .../tests/translator_integration.rs | 4 ++ 5 files changed, 80 insertions(+) diff --git a/roles/Cargo.lock b/roles/Cargo.lock index 21a79749ef..5b06244349 100644 --- a/roles/Cargo.lock +++ b/roles/Cargo.lock @@ -75,6 +75,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -1421,6 +1430,7 @@ dependencies = [ "tar", "tokio", "tracing", + "tracing-subscriber", "translator_sv2", ] @@ -1604,6 +1614,15 @@ dependencies = [ "value-bag", ] +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.7.4" @@ -2115,6 +2134,50 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.9", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.5", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "ring" version = "0.17.8" @@ -2728,10 +2791,14 @@ version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8189decb5ac0fa7bc8b96b7cb9b2701d60d48805aca84a238004d665fcc4008" dependencies = [ + "matchers", "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", "smallvec", "thread_local", + "tracing", "tracing-core", "tracing-log", ] diff --git a/roles/tests-integration/Cargo.toml b/roles/tests-integration/Cargo.toml index 262907dd64..6b141f0f2a 100644 --- a/roles/tests-integration/Cargo.toml +++ b/roles/tests-integration/Cargo.toml @@ -33,6 +33,7 @@ tracing = "0.1.40" translator_sv2 = { path = "../translator" } rand = "0.8.4" stratum-common = { path = "../../common" } +tracing-subscriber = { version = "0.3.19", features = ["env-filter"] } [lib] path = "lib/mod.rs" diff --git a/roles/tests-integration/tests/pool_integration.rs b/roles/tests-integration/tests/pool_integration.rs index 94c832a0dd..daf378c081 100644 --- a/roles/tests-integration/tests/pool_integration.rs +++ b/roles/tests-integration/tests/pool_integration.rs @@ -1,4 +1,5 @@ use integration_tests_sv2::*; +use tracing_subscriber::EnvFilter; use crate::sniffer::MessageDirection; use const_sv2::{ @@ -16,6 +17,9 @@ use roles_logic_sv2::{ // Pool will connect to the Sniffer, and the Sniffer will connect to the Template Provider. #[tokio::test] async fn success_pool_template_provider_connection() { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (_tp, tp_addr) = start_template_provider(None).await; let (sniffer, sniffer_addr) = start_sniffer("".to_string(), tp_addr, true, None).await; let _ = start_pool(Some(sniffer_addr)).await; diff --git a/roles/tests-integration/tests/sniffer_integration.rs b/roles/tests-integration/tests/sniffer_integration.rs index d6be3d3eb3..46962eb420 100644 --- a/roles/tests-integration/tests/sniffer_integration.rs +++ b/roles/tests-integration/tests/sniffer_integration.rs @@ -9,6 +9,7 @@ use roles_logic_sv2::{ }; use sniffer::{InterceptMessage, MessageDirection}; use std::convert::TryInto; +use tracing_subscriber::EnvFilter; // This test aims to assert that Sniffer is able to intercept and replace some messages. // sniffer_a replaces a SetupConnectionSuccess from TP with a SetupConnectionError directed at Pool @@ -16,6 +17,9 @@ use std::convert::TryInto; // TP -> sniffer_a -> sniffer_b -> Pool #[tokio::test] async fn test_sniffer_intercept_to_downstream() { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (_tp, tp_addr) = start_template_provider(None).await; let message_replacement = PoolMessages::Common(CommonMessages::SetupConnectionError(SetupConnectionError { diff --git a/roles/tests-integration/tests/translator_integration.rs b/roles/tests-integration/tests/translator_integration.rs index 6aabfb4cab..3fbb805edb 100644 --- a/roles/tests-integration/tests/translator_integration.rs +++ b/roles/tests-integration/tests/translator_integration.rs @@ -1,6 +1,7 @@ use const_sv2::{MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SUBMIT_SHARES_EXTENDED}; use integration_tests_sv2::{sniffer::*, *}; use roles_logic_sv2::parsers::{CommonMessages, Mining, PoolMessages}; +use tracing_subscriber::EnvFilter; // This test runs an sv2 translator between an sv1 mining device and a pool. the connection between // the translator and the pool is intercepted by a sniffer. The test checks if the translator and @@ -8,6 +9,9 @@ use roles_logic_sv2::parsers::{CommonMessages, Mining, PoolMessages}; // shares. #[tokio::test] async fn translation_proxy() { + tracing_subscriber::fmt() + .with_env_filter(EnvFilter::from_default_env()) + .init(); let (_tp, tp_addr) = start_template_provider(None).await; let (_pool, pool_addr) = start_pool(Some(tp_addr)).await; let (pool_translator_sniffer, pool_translator_sniffer_addr) =