Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracing-subscriber to itf #1430

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- ubuntu-latest
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
target: x86_64-unknown-linux-gnu

steps:
- name: Use stable toolchain
Expand All @@ -26,4 +26,4 @@ jobs:

- name: Roles Integration Tests
run: |
cargo test --manifest-path=roles/Cargo.toml --verbose --test '*' -- --nocapture
RUST_LOG=debug cargo test --manifest-path=roles/Cargo.toml --verbose --test '*' -- --nocapture
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"
15 changes: 13 additions & 2 deletions roles/tests-integration/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,31 @@ use jd_client::JobDeclaratorClient;
use jd_server::JobDeclaratorServer;
use key_utils::{Secp256k1PublicKey, Secp256k1SecretKey};
use pool_sv2::PoolSv2;
use translator_sv2::TranslatorSv2;

use rand::{thread_rng, Rng};
use std::{
convert::{TryFrom, TryInto},
net::SocketAddr,
str::FromStr,
sync::Once,
};
use tracing_subscriber::EnvFilter;
use translator_sv2::TranslatorSv2;
use utils::get_available_address;

pub mod sniffer;
pub mod template_provider;
mod utils;

static LOGGER: Once = Once::new();

pub fn start_tracing() {
LOGGER.call_once(|| {
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.init();
plebhash marked this conversation as resolved.
Show resolved Hide resolved
});
}

pub async fn start_sniffer(
identifier: String,
upstream: SocketAddr,
Expand Down
10 changes: 8 additions & 2 deletions roles/tests-integration/tests/jd_integration.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// This file contains integration tests for the `JDC/S` module.
//
// `JDC/S` are modules that implements the Job Decleration roles in the Stratum V2 protocol.
//
// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for
// all tests. This is because tracing is a global setting.
use integration_tests_sv2::*;

use roles_logic_sv2::parsers::{CommonMessages, PoolMessages};

// This test verifies that the `jds` (Job Distributor Server) does not panic when the `jdc`
// (Job Distributor Client) shuts down.
// This test verifies that the `jds` (Job Decleration Server) does not panic when the `jdc`
// (Job Decleration Client) shuts down.
//
// The test follows these steps:
// 1. Start a Template Provider (`tp`) and a Pool.
Expand Down
10 changes: 8 additions & 2 deletions roles/tests-integration/tests/pool_integration.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use integration_tests_sv2::*;

// This file contains integration tests for the `PoolSv2` module.
//
// `PoolSv2` is a module that implements the Pool role in the Stratum V2 protocol.
//
// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for
// all tests. This is because tracing is a global setting.
use crate::sniffer::MessageDirection;
use const_sv2::{
MESSAGE_TYPE_MINING_SET_NEW_PREV_HASH, MESSAGE_TYPE_NEW_EXTENDED_MINING_JOB,
MESSAGE_TYPE_NEW_TEMPLATE,
};
use integration_tests_sv2::*;
use roles_logic_sv2::{
common_messages_sv2::{Protocol, SetupConnection},
parsers::{AnyMessage, CommonMessages, Mining, PoolMessages, TemplateDistribution},
Expand All @@ -16,6 +21,7 @@ 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() {
start_tracing();
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
9 changes: 9 additions & 0 deletions roles/tests-integration/tests/sniffer_integration.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// This file contains integration tests for the `Sniffer` module.
//
// `Sniffer` is a useful tool to perform Man-in-the-Middle setups for testing purposes. It can
// intercept messages and replace them with others, as well as assert that certain messages were
// received.
//
// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for
// all tests. This is because tracing is a global setting.
use const_sv2::{
MESSAGE_TYPE_SETUP_CONNECTION, MESSAGE_TYPE_SETUP_CONNECTION_SUCCESS,
MESSAGE_TYPE_SET_NEW_PREV_HASH,
Expand All @@ -16,6 +24,7 @@ use std::convert::TryInto;
// TP -> sniffer_a -> sniffer_b -> Pool
#[tokio::test]
async fn test_sniffer_intercept_to_downstream() {
start_tracing();
let (_tp, tp_addr) = start_template_provider(None).await;
let message_replacement =
PoolMessages::Common(CommonMessages::SetupConnectionError(SetupConnectionError {
Expand Down
9 changes: 8 additions & 1 deletion roles/tests-integration/tests/translator_integration.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// This file contains integration tests for the `TranslatorSv2` module.
//
// `TranslatorSv2` is a module that implements the Translator role in the Stratum V2 protocol.
//
// Note that it is enough to call `start_tracing()` once in the test suite to enable tracing for
// all tests. This is because tracing is a global setting.
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};
Expand All @@ -7,7 +13,8 @@ use roles_logic_sv2::parsers::{CommonMessages, Mining, PoolMessages};
// the pool exchange the correct messages upon connection. And that the miner is able to submit
// shares.
#[tokio::test]
async fn translation_proxy() {
async fn translate_sv1_to_sv2_successfully() {
start_tracing();
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
Loading