Skip to content

Commit

Permalink
Add tracing-subscriber to testing
Browse files Browse the repository at this point in the history
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 '*'`
  • Loading branch information
jbesraa committed Jan 31, 2025
1 parent 84dbb48 commit 2ba08cc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
67 changes: 67 additions & 0 deletions roles/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions roles/tests-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 4 additions & 0 deletions roles/tests-integration/tests/pool_integration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use integration_tests_sv2::*;
use tracing_subscriber::EnvFilter;

use crate::sniffer::MessageDirection;
use const_sv2::{
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions roles/tests-integration/tests/sniffer_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ 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
// sniffer_b asserts that Pool is about to receive a SetupConnectionError
// TP -> sniffer_a -> sniffer_b -> Pool
#[tokio::test]
async fn test_sniffer_intercept() {
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 {
Expand Down
4 changes: 4 additions & 0 deletions roles/tests-integration/tests/translator_integration.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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
// the pool exchange the correct messages upon connection. And that the miner is able to submit
// 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) =
Expand Down

0 comments on commit 2ba08cc

Please sign in to comment.