Enable tracing in monero-harness

This commit is contained in:
Daniel Karzel 2021-01-11 12:55:19 +11:00
parent 664958939d
commit bfc388d264
5 changed files with 41 additions and 0 deletions

2
Cargo.lock generated
View File

@ -1945,6 +1945,8 @@ dependencies = [
"testcontainers", "testcontainers",
"tokio", "tokio",
"tracing", "tracing",
"tracing-log",
"tracing-subscriber",
"url", "url",
] ]

View File

@ -17,4 +17,6 @@ spectral = "0.6"
testcontainers = "0.11" testcontainers = "0.11"
tokio = { version = "0.2", default-features = false, features = ["blocking", "macros", "rt-core", "time"] } tokio = { version = "0.2", default-features = false, features = ["blocking", "macros", "rt-core", "time"] }
tracing = "0.1" tracing = "0.1"
tracing-log = "0.1"
tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "ansi", "env-filter"] }
url = "2" url = "2"

View File

@ -1,11 +1,16 @@
use crate::testutils::init_tracing;
use monero_harness::Monero; use monero_harness::Monero;
use spectral::prelude::*; use spectral::prelude::*;
use std::time::Duration; use std::time::Duration;
use testcontainers::clients::Cli; use testcontainers::clients::Cli;
use tokio::time; use tokio::time;
mod testutils;
#[tokio::test] #[tokio::test]
async fn init_miner_and_mine_to_miner_address() { async fn init_miner_and_mine_to_miner_address() {
let _guard = init_tracing();
let tc = Cli::default(); let tc = Cli::default();
let (monero, _monerod_container) = Monero::new(&tc, None, vec![]).await.unwrap(); let (monero, _monerod_container) = Monero::new(&tc, None, vec![]).await.unwrap();

View File

@ -0,0 +1,27 @@
use tracing::subscriber::DefaultGuard;
use tracing_log::LogTracer;
/// Utility function to initialize logging in the test environment.
/// Note that you have to keep the `_guard` in scope after calling in test:
///
/// ```rust
/// let _guard = init_tracing();
/// ```
pub fn init_tracing() -> DefaultGuard {
// converts all log records into tracing events
// Note: Make sure to initialize without unwrapping, otherwise this causes
// trouble when running multiple tests.
let _ = LogTracer::init();
let global_filter = tracing::Level::WARN;
let test_filter = tracing::Level::DEBUG;
let monero_harness_filter = tracing::Level::INFO;
use tracing_subscriber::util::SubscriberInitExt as _;
tracing_subscriber::fmt()
.with_env_filter(format!(
"{},test={},monero_harness={}",
global_filter, test_filter, monero_harness_filter,
))
.set_default()
}

View File

@ -1,9 +1,14 @@
use crate::testutils::init_tracing;
use monero_harness::Monero; use monero_harness::Monero;
use spectral::prelude::*; use spectral::prelude::*;
use testcontainers::clients::Cli; use testcontainers::clients::Cli;
mod testutils;
#[tokio::test] #[tokio::test]
async fn fund_transfer_and_check_tx_key() { async fn fund_transfer_and_check_tx_key() {
let _guard = init_tracing();
let fund_alice: u64 = 1_000_000_000_000; let fund_alice: u64 = 1_000_000_000_000;
let fund_bob = 0; let fund_bob = 0;
let send_to_bob = 5_000_000_000; let send_to_bob = 5_000_000_000;