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

Followup for the "use tracing" PR #1191

Merged
merged 2 commits into from
Sep 21, 2023
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
11 changes: 11 additions & 0 deletions 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ cfg-if = "1.0"
chacha20poly1305 = "0.10"
chrono = "0.4"
clap = "4"
ctor = "0.2"
criterion = "0.5"
crossterm = "0.27"
derive_more = "0.99"
Expand Down
2 changes: 1 addition & 1 deletion api-server/scanner-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async fn main() -> Result<(), ApiServerScannerError> {

let args = ApiServerScannerArgs::parse();

logging::init_logging::<&std::path::Path>(None);
logging::init_logging();
logging::log::info!("Command line options: {args:?}");

let ApiServerScannerArgs {
Expand Down
2 changes: 1 addition & 1 deletion api-server/web-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() {
std::env::set_var("RUST_LOG", "info");
}

logging::init_logging::<&std::path::Path>(None);
logging::init_logging();

let args = ApiServerWebServerConfig::parse();
log::info!("Command line options: {args:?}");
Expand Down
2 changes: 1 addition & 1 deletion common/src/primitives/encoding/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use logging::log;

#[test]
fn check_encode() {
logging::init_logging::<&std::path::Path>(None);
logging::init_logging();

let data = vec![0x00, 0x01, 0x02].check_base32().unwrap();
let hrp = "bech32";
Expand Down
2 changes: 1 addition & 1 deletion common/src/primitives/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod tests {
#[test]
#[serial_test::serial]
fn test_time() {
logging::init_logging::<&std::path::Path>(None);
logging::init_logging();
set(Duration::from_secs(1337)).unwrap();

log::info!("p2p time: {}", get_time().as_secs());
Expand Down
2 changes: 1 addition & 1 deletion dns_server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async fn run(config: Arc<DnsServerConfig>) -> Result<Never, error::DnsServerErro
async fn main() {
utils::rust_backtrace::enable();

logging::init_logging::<std::path::PathBuf>(None);
logging::init_logging();

let config = Arc::new(DnsServerConfig::parse());

Expand Down
14 changes: 3 additions & 11 deletions logging/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,8 @@ pub use log;

pub use tracing_utils::spawn_in_current_span;

pub fn is_only_terminal_output_logging() -> bool {
true
}

pub fn is_file_output_supported() -> bool {
false
}

/// Send log output to the terminal.
pub fn init_logging<P: AsRef<std::path::Path>>(_: Option<P>) {
pub fn init_logging() {
init_logging_impl(
// Write to stderr to mimic the behavior of env_logger.
std::io::stderr,
Expand Down Expand Up @@ -110,7 +102,7 @@ mod tests {

#[test]
fn initialize_twice() {
init_logging::<&std::path::Path>(None);
init_logging::<&std::path::Path>(None);
init_logging();
init_logging();
}
}
2 changes: 1 addition & 1 deletion mempool/src/pool/tests/expiry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use ::utils::atomics::SeqCstAtomicU64;
async fn descendant_of_expired_entry(#[case] seed: Seed) -> anyhow::Result<()> {
let mock_time = Arc::new(SeqCstAtomicU64::new(0));
let mock_clock = mocked_time_getter_seconds(Arc::clone(&mock_time));
logging::init_logging::<&str>(None);
logging::init_logging();

let mut rng = make_seedable_rng(seed);
let tf = TestFramework::builder(&mut rng).build();
Expand Down
12 changes: 6 additions & 6 deletions mempool/src/pool/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const HUGE_MAX_TIP_AGE: MaxTipAge = MaxTipAge::new(Duration::from_secs(100 * 365

#[test]
fn dummy_size() {
logging::init_logging::<&str>(None);
logging::init_logging();
log::debug!("1, 1: {}", estimate_tx_size(1, 1));
log::debug!("1, 2: {}", estimate_tx_size(1, 2));
log::debug!("1, 400: {}", estimate_tx_size(1, 400));
Expand Down Expand Up @@ -209,7 +209,7 @@ pub fn start_chainstate_with_config(
}

fn setup() -> Mempool<StoreMemoryUsageEstimator> {
logging::init_logging::<&str>(None);
logging::init_logging();
let config = Arc::new(common::chain::config::create_unit_test_config());
let chainstate_interface = start_chainstate_with_config(Arc::clone(&config));
Mempool::new(
Expand All @@ -223,7 +223,7 @@ fn setup() -> Mempool<StoreMemoryUsageEstimator> {
fn setup_with_chainstate(
chainstate: Box<dyn ChainstateInterface>,
) -> Mempool<StoreMemoryUsageEstimator> {
logging::init_logging::<&str>(None);
logging::init_logging();
let config = Arc::new(common::chain::config::create_unit_test_config());
let chainstate_handle = start_chainstate(chainstate);
Mempool::new(
Expand Down Expand Up @@ -879,7 +879,7 @@ async fn spends_new_unconfirmed(#[case] seed: Seed) -> anyhow::Result<()> {
#[case(Seed::from_entropy())]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn rolling_fee(#[case] seed: Seed) -> anyhow::Result<()> {
logging::init_logging::<&str>(None);
logging::init_logging();
let mock_time = Arc::new(SeqCstAtomicU64::new(0));
let mock_clock = mocked_time_getter_seconds(Arc::clone(&mock_time));
let mut mock_usage = MockMemoryUsageEstimator::new();
Expand Down Expand Up @@ -1513,7 +1513,7 @@ fn check_txs_sorted_by_descendant_sore<M>(mempool: &Mempool<M>) {
#[case(Seed::from_entropy())]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn mempool_full_mock(#[case] seed: Seed) -> anyhow::Result<()> {
logging::init_logging::<&str>(None);
logging::init_logging();

let mut rng = make_seedable_rng(seed);
let tf = TestFramework::builder(&mut rng).build();
Expand Down Expand Up @@ -1557,7 +1557,7 @@ async fn mempool_full_mock(#[case] seed: Seed) -> anyhow::Result<()> {
#[case::fail(Seed(1))]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn mempool_full_real(#[case] seed: Seed) {
logging::init_logging::<&str>(None);
logging::init_logging();
let mut rng = make_seedable_rng(seed);

let num_txs = rng.gen_range(5..20);
Expand Down
4 changes: 2 additions & 2 deletions mempool/src/pool/work_queue/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl PeerIdSupply {
#[trace]
#[case(Seed::from_entropy())]
fn simulation(#[case] seed: Seed) {
logging::init_logging::<&str>(None);
logging::init_logging();
let mut rng = make_seedable_rng(seed);
let mut peer_supply = PeerIdSupply::new();

Expand Down Expand Up @@ -198,7 +198,7 @@ fn scheduling_fairness_full_queues(#[case] seed: Seed) {
// Minimum number of work items in each peer's queue at the start
const MIN_WORK: usize = 100;

logging::init_logging::<&str>(None);
logging::init_logging();
let mut rng = make_seedable_rng(seed);
let num_peers: usize = rng.gen_range(2..=8);
let peer1 = PeerId::from_u64(1);
Expand Down
2 changes: 1 addition & 1 deletion node-daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

pub async fn run() -> anyhow::Result<()> {
let opts = node_lib::Options::from_args(std::env::args_os());
logging::init_logging::<&std::path::Path>(None);
logging::init_logging();
logging::log::info!("Command line options: {opts:?}");
let node = node_lib::setup(opts).await?;
node.main().await;
Expand Down
2 changes: 1 addition & 1 deletion node-gui/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub async fn node_initialize(_time_getter: TimeGetter) -> anyhow::Result<Backend
}

let opts = node_lib::Options::from_args(std::env::args_os());
logging::init_logging::<&std::path::Path>(None);
logging::init_logging();
logging::log::info!("Command line options: {opts:?}");

let node = node_lib::setup(opts).await?;
Expand Down
2 changes: 1 addition & 1 deletion node-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ pub fn default_rpc_config() -> RpcConfigFile {
}

pub fn init_logging(_opts: &Options) {
logging::init_logging::<&std::path::Path>(None)
logging::init_logging()
}
1 change: 1 addition & 0 deletions p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ storage-inmemory = { path = "../storage/inmemory" }
test-utils = { path = "../test-utils" }

criterion.workspace = true
ctor.workspace = true
portpicker.workspace = true
rstest.workspace = true

Expand Down
1 change: 1 addition & 0 deletions p2p/backend-test-suite/src/ban.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tests![invalid_pubsub_block,];
// invalid block from the first service and verify that the `SyncManager` of the first service
// receives a `AdjustPeerScore` event which bans the peer of the second service.
#[allow(clippy::extra_unused_type_parameters)]
#[tracing::instrument]
async fn invalid_pubsub_block<T, N>()
where
T: TestTransportMaker<Transport = N::Transport>,
Expand Down
2 changes: 2 additions & 0 deletions p2p/backend-test-suite/src/block_announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use utils::atomics::SeqCstAtomicBool;
tests![block_announcement, block_announcement_no_subscription,];

#[allow(clippy::extra_unused_type_parameters)]
#[tracing::instrument]
async fn block_announcement<T, N>()
where
T: TestTransportMaker<Transport = N::Transport>,
Expand Down Expand Up @@ -157,6 +158,7 @@ where
}

#[allow(clippy::extra_unused_type_parameters)]
#[tracing::instrument]
async fn block_announcement_no_subscription<T, N>()
where
T: TestTransportMaker<Transport = N::Transport>,
Expand Down
3 changes: 3 additions & 0 deletions p2p/backend-test-suite/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use utils::atomics::SeqCstAtomicBool;
tests![connect, connect_address_in_use, connect_accept,];

#[allow(clippy::extra_unused_type_parameters)]
#[tracing::instrument]
async fn connect<T, N>()
where
T: TestTransportMaker<Transport = N::Transport>,
Expand Down Expand Up @@ -63,6 +64,7 @@ where

// Check that connecting twice to the same address isn't possible.
#[allow(clippy::extra_unused_type_parameters)]
#[tracing::instrument]
async fn connect_address_in_use<T, N>()
where
T: TestTransportMaker<Transport = N::Transport>,
Expand Down Expand Up @@ -120,6 +122,7 @@ where
// Try to connect two nodes by having `service1` listen for network events and having `service2`
// trying to connect to `service1`.
#[allow(clippy::extra_unused_type_parameters)]
#[tracing::instrument]
async fn connect_accept<T, N>()
where
T: TestTransportMaker<Transport = N::Transport>,
Expand Down
1 change: 1 addition & 0 deletions p2p/backend-test-suite/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use utils::atomics::SeqCstAtomicBool;
tests![peer_events,];

#[allow(clippy::extra_unused_type_parameters)]
#[tracing::instrument]
async fn peer_events<T, N>()
where
T: TestTransportMaker<Transport = N::Transport>,
Expand Down
2 changes: 1 addition & 1 deletion p2p/backend-test-suite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
N::SyncingEventReceiver: SyncingEventReceiver + Debug,
{
rlimit::increase_nofile_limit(10 * 1024).unwrap();
logging::init_logging::<&str>(None);
logging::init_logging();
let args = Arguments::from_args();
libtest_mimic::run(&args, tests::<T, N>()).exit();
}
Expand Down
12 changes: 12 additions & 0 deletions p2p/src/net/default_backend/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,19 @@ mod tests {
);
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_inbound_tcp() {
handshake_inbound::<TestTransportTcp, TcpTransportSocket>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_inbound_channels() {
handshake_inbound::<TestTransportChannel, MpscChannelTransport>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_inbound_noise() {
handshake_inbound::<TestTransportNoise, NoiseTcpTransport>().await;
Expand Down Expand Up @@ -516,16 +519,19 @@ mod tests {
);
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_outbound_tcp() {
handshake_outbound::<TestTransportTcp, TcpTransportSocket>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_outbound_channels() {
handshake_outbound::<TestTransportChannel, MpscChannelTransport>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_outbound_noise() {
handshake_outbound::<TestTransportNoise, NoiseTcpTransport>().await;
Expand Down Expand Up @@ -578,16 +584,19 @@ mod tests {
assert_eq!(handle.await.unwrap(), Ok(()));
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_different_network_tcp() {
handshake_different_network::<TestTransportTcp, TcpTransportSocket>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_different_network_channels() {
handshake_different_network::<TestTransportChannel, MpscChannelTransport>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn handshake_different_network_noise() {
handshake_different_network::<TestTransportNoise, NoiseTcpTransport>().await;
Expand Down Expand Up @@ -636,16 +645,19 @@ mod tests {
),);
}

#[tracing::instrument]
#[tokio::test]
async fn invalid_handshake_message_tcp() {
invalid_handshake_message::<TestTransportTcp, TcpTransportSocket>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn invalid_handshake_message_channels() {
invalid_handshake_message::<TestTransportChannel, MpscChannelTransport>().await;
}

#[tracing::instrument]
#[tokio::test]
async fn invalid_handshake_message_noise() {
invalid_handshake_message::<TestTransportNoise, NoiseTcpTransport>().await;
Expand Down
Loading
Loading