From 5003021c17bd85aadab587488fff36e8a218ae32 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Sun, 3 Nov 2019 00:18:47 +0100 Subject: [PATCH] [tests] common-tests-tools: ensure to init logger once --- .../ws2p/ws2p/tests/connection_negociation.rs | 12 ++---------- lib/tests-tools/common-tests-tools/src/logger.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/modules/ws2p/ws2p/tests/connection_negociation.rs b/lib/modules/ws2p/ws2p/tests/connection_negociation.rs index 88d9a79d..06ceb610 100644 --- a/lib/modules/ws2p/ws2p/tests/connection_negociation.rs +++ b/lib/modules/ws2p/ws2p/tests/connection_negociation.rs @@ -28,20 +28,12 @@ use durs_ws2p_protocol::controller::{WS2PControllerEvent, WebsocketActionOrder}; use durs_ws2p_protocol::orchestrator::OrchestratorMsg; use durs_ws2p_protocol::MySelfWs2pNode; use std::sync::mpsc; -use std::sync::Once; use std::thread; use std::time::Duration; static PORT: &'static u16 = &10899; -static SETUP: Once = Once::new(); static TIMEOUT_IN_MS: &'static u64 = &20_000; -fn setup() { - SETUP.call_once(|| { - durs_common_tests_tools::logger::init_logger_stdout(vec!["ws"]); - }); -} - pub fn currency() -> CurrencyName { CurrencyName(String::from("g1")) } @@ -82,7 +74,7 @@ fn client_node() -> MySelfWs2pNode { #[test] #[cfg(unix)] fn test_connection_negociation_denial() { - setup(); + durs_common_tests_tools::logger::init_logger_stdout(vec!["ws"]); // ===== initialization ===== // client and server are initialized and launched in separate threads @@ -159,7 +151,7 @@ fn test_connection_negociation_denial() { #[test] #[cfg(unix)] fn test_connection_negociation_success() { - setup(); + durs_common_tests_tools::logger::init_logger_stdout(vec!["ws"]); // ===== initialization ===== // client and server are initialized and launched in separate threads diff --git a/lib/tests-tools/common-tests-tools/src/logger.rs b/lib/tests-tools/common-tests-tools/src/logger.rs index 7eadbd24..ced8980b 100644 --- a/lib/tests-tools/common-tests-tools/src/logger.rs +++ b/lib/tests-tools/common-tests-tools/src/logger.rs @@ -17,9 +17,18 @@ use fern::colors::{Color, ColoredLevelConfig}; use log::LevelFilter; +use std::sync::Once; + +static ONCE: Once = Once::new(); /// Initialize stdout logger pub fn init_logger_stdout(off_targets: Vec<&'static str>) { + ONCE.call_once(|| { + init_logger_stdout_(off_targets); + }); +} + +fn init_logger_stdout_(off_targets: Vec<&'static str>) { let colors = match std::env::var("DURS_TESTS_LOG_COLOR") .unwrap_or_else(|_| String::from("no")) .as_str() -- GitLab