Fixed tracing
setup in tests
This commit is contained in:
parent
7911336f70
commit
7d7ff22526
4 changed files with 29 additions and 12 deletions
|
@ -2,3 +2,16 @@ pub mod api;
|
||||||
pub mod messages;
|
pub mod messages;
|
||||||
pub mod peer;
|
pub mod peer;
|
||||||
pub mod types;
|
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(),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
@ -102,7 +102,8 @@ impl ApiState {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use ubisync_lib::types::ElementContent;
|
use tracing::Level;
|
||||||
|
use ubisync_lib::{types::ElementContent, tracing_setup};
|
||||||
|
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
|
|
||||||
|
@ -111,7 +112,8 @@ mod tests {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial_test::serial]
|
#[serial_test::serial]
|
||||||
async fn test_element_create() {
|
async fn test_element_create() {
|
||||||
tracing_subscriber::fmt().pretty().init();
|
tracing_setup!(Level::DEBUG);
|
||||||
|
|
||||||
let state = ApiState::new(
|
let state = ApiState::new(
|
||||||
State::new().await.unwrap(),
|
State::new().await.unwrap(),
|
||||||
"abcdabcdabcdabcdabcdabcdabcdabcd",
|
"abcdabcdabcdabcdabcdabcdabcdabcd",
|
||||||
|
@ -129,7 +131,8 @@ mod tests {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial_test::serial]
|
#[serial_test::serial]
|
||||||
async fn test_element_write() {
|
async fn test_element_write() {
|
||||||
tracing_subscriber::fmt().pretty().init();
|
tracing_setup!(Level::DEBUG);
|
||||||
|
|
||||||
let state = ApiState::new(
|
let state = ApiState::new(
|
||||||
State::new().await.unwrap(),
|
State::new().await.unwrap(),
|
||||||
"abcdabcdabcdabcdabcdabcdabcdabcd",
|
"abcdabcdabcdabcdabcdabcdabcdabcd",
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl CommState {
|
||||||
|
|
||||||
pub fn set_peer(&self, id: &PeerId, name: &str) -> anyhow::Result<()> {
|
pub fn set_peer(&self, id: &PeerId, name: &str) -> anyhow::Result<()> {
|
||||||
queries::peers::put(self.db(), id, name)?;
|
queries::peers::put(self.db(), id, name)?;
|
||||||
debug!("Set peer {{{}}}", id.to_string());
|
debug!("Set peer {} with address {}.", &name, id.to_string());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -84,12 +84,14 @@ mod tests {
|
||||||
|
|
||||||
use super::CommState;
|
use super::CommState;
|
||||||
|
|
||||||
use ubisync_lib::types::{ElementContent, ElementId, MessageId};
|
use tracing::Level;
|
||||||
|
use ubisync_lib::{types::{ElementContent, ElementId, MessageId}, tracing_setup};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial_test::serial]
|
#[serial_test::serial]
|
||||||
async fn test_element_add() {
|
async fn test_element_add() {
|
||||||
tracing_subscriber::fmt().pretty().init();
|
tracing_setup!(Level::DEBUG);
|
||||||
|
|
||||||
let state = CommState::new(State::new().await.unwrap());
|
let state = CommState::new(State::new().await.unwrap());
|
||||||
let id = ElementId::new();
|
let id = ElementId::new();
|
||||||
state
|
state
|
||||||
|
@ -109,7 +111,8 @@ mod tests {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
#[serial_test::serial]
|
#[serial_test::serial]
|
||||||
async fn test_element_update() {
|
async fn test_element_update() {
|
||||||
tracing_subscriber::fmt().pretty().init();
|
tracing_setup!(Level::DEBUG);
|
||||||
|
|
||||||
let state = CommState::new(State::new().await.unwrap());
|
let state = CommState::new(State::new().await.unwrap());
|
||||||
let id = ElementId::new();
|
let id = ElementId::new();
|
||||||
state
|
state
|
||||||
|
|
|
@ -4,16 +4,14 @@ use tracing::{debug, warn, Level};
|
||||||
use ubisync::{config::Config, Ubisync};
|
use ubisync::{config::Config, Ubisync};
|
||||||
use ubisync_lib::{
|
use ubisync_lib::{
|
||||||
api::element::{ElementCreateRequest, ElementGetRequest},
|
api::element::{ElementCreateRequest, ElementGetRequest},
|
||||||
types::{Element, ElementContent},
|
types::{Element, ElementContent}, tracing_setup,
|
||||||
};
|
};
|
||||||
use ubisync_sdk::UbisyncClient;
|
use ubisync_sdk::UbisyncClient;
|
||||||
|
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread")]
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
async fn two_nodes_element_creation() {
|
async fn two_nodes_element_creation() {
|
||||||
tracing_subscriber::fmt()
|
tracing_setup!(Level::DEBUG);
|
||||||
.pretty()
|
|
||||||
.with_max_level(Level::DEBUG)
|
|
||||||
.init();
|
|
||||||
|
|
||||||
// Two nodes need to bind to different ports
|
// Two nodes need to bind to different ports
|
||||||
let mut c2 = Config::default();
|
let mut c2 = Config::default();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue