Skip to content

Commit

Permalink
use atomic compare exchange to only initialize tracing once during tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xoloki committed Oct 3, 2023
1 parent 8e292c8 commit 80b6cac
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,8 +1294,8 @@ mod test {
use hashbrown::HashMap;
use p256k1::{ecdsa, point::Point, scalar::Scalar};
use rand_core::{CryptoRng, OsRng, RngCore};
use std::sync::atomic::{AtomicBool, Ordering};

//use crate::runloop::process_inbound_messages;
use crate::{
common::PolyCommitment,
net::{DkgPublicShares, DkgStatus, Message, Packet},
Expand All @@ -1309,6 +1309,8 @@ mod test {
v1, v2,
};

static mut LOG_INIT: AtomicBool = AtomicBool::new(false);

#[test]
fn test_coordinator_state_machine_v1() {
test_coordinator_state_machine::<v1::Aggregator>();
Expand Down Expand Up @@ -1521,10 +1523,15 @@ mod test {

fn setup<Aggregator: AggregatorTrait, Signer: SignerTrait>(
) -> (Coordinator<Aggregator>, Vec<SigningRound<Signer>>) {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_target(true)
.init();
unsafe {
match LOG_INIT.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) {
Ok(true) => tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.with_target(true)
.init(),
_ => {}
}
}

let mut rng = OsRng;
let total_signers = 5;
Expand Down

0 comments on commit 80b6cac

Please sign in to comment.