Fixed tracing setup in tests

This commit is contained in:
Philip (a-0) 2024-01-07 22:09:00 +01:00
parent 7911336f70
commit 7d7ff22526
4 changed files with 29 additions and 12 deletions

View file

@ -2,3 +2,16 @@ pub mod api;
pub mod messages;
pub mod peer;
pub mod types;
#[macro_export]
macro_rules! tracing_setup {
($level:expr) => {
let _tracing_default_guard = tracing::subscriber::set_default(
tracing_subscriber::fmt()
.pretty()
.with_max_level($level)
.finish(),
);
};
}

View file

@ -102,7 +102,8 @@ impl ApiState {
#[cfg(test)]
mod tests {
use ubisync_lib::types::ElementContent;
use tracing::Level;
use ubisync_lib::{types::ElementContent, tracing_setup};
use crate::state::State;
@ -111,7 +112,8 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn test_element_create() {
tracing_subscriber::fmt().pretty().init();
tracing_setup!(Level::DEBUG);
let state = ApiState::new(
State::new().await.unwrap(),
"abcdabcdabcdabcdabcdabcdabcdabcd",
@ -129,7 +131,8 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn test_element_write() {
tracing_subscriber::fmt().pretty().init();
tracing_setup!(Level::DEBUG);
let state = ApiState::new(
State::new().await.unwrap(),
"abcdabcdabcdabcdabcdabcdabcdabcd",

View file

@ -64,7 +64,7 @@ impl CommState {
pub fn set_peer(&self, id: &PeerId, name: &str) -> anyhow::Result<()> {
queries::peers::put(self.db(), id, name)?;
debug!("Set peer {{{}}}", id.to_string());
debug!("Set peer {} with address {}.", &name, id.to_string());
Ok(())
}
@ -84,12 +84,14 @@ mod tests {
use super::CommState;
use ubisync_lib::types::{ElementContent, ElementId, MessageId};
use tracing::Level;
use ubisync_lib::{types::{ElementContent, ElementId, MessageId}, tracing_setup};
#[tokio::test]
#[serial_test::serial]
async fn test_element_add() {
tracing_subscriber::fmt().pretty().init();
tracing_setup!(Level::DEBUG);
let state = CommState::new(State::new().await.unwrap());
let id = ElementId::new();
state
@ -109,7 +111,8 @@ mod tests {
#[tokio::test]
#[serial_test::serial]
async fn test_element_update() {
tracing_subscriber::fmt().pretty().init();
tracing_setup!(Level::DEBUG);
let state = CommState::new(State::new().await.unwrap());
let id = ElementId::new();
state

View file

@ -4,16 +4,14 @@ use tracing::{debug, warn, Level};
use ubisync::{config::Config, Ubisync};
use ubisync_lib::{
api::element::{ElementCreateRequest, ElementGetRequest},
types::{Element, ElementContent},
types::{Element, ElementContent}, tracing_setup,
};
use ubisync_sdk::UbisyncClient;
#[tokio::test(flavor = "multi_thread")]
async fn two_nodes_element_creation() {
tracing_subscriber::fmt()
.pretty()
.with_max_level(Level::DEBUG)
.init();
tracing_setup!(Level::DEBUG);
// Two nodes need to bind to different ports
let mut c2 = Config::default();