Skip to content

Commit

Permalink
Merge pull request #73 from fjarri/test-log
Browse files Browse the repository at this point in the history
Remove `run_sync_with_tracing` in favor of using `test_log` where necessary
  • Loading branch information
fjarri authored Nov 19, 2024
2 parents 6bec7fc + 65d00a6 commit 317d8fe
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 41 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `EntryPoint::ENTRY_ROUND` constant. ([#60])
- `Round::echo_round_participation()`. ([#67])
- `SessionReport::result()`. ([#71])
- `run_sync_with_tracing()`. ([#71])


[#32]: https://github.com/entropyxyz/manul/pull/32
Expand Down
113 changes: 105 additions & 8 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 examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ tokio = { version = "1", features = ["rt", "sync", "time", "macros"] }
rand = "0.8"
digest = "0.10"
manul = { path = "../manul", features = ["dev"] }
test-log = { version = "0.2", features = ["trace", "color"] }
5 changes: 3 additions & 2 deletions examples/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,11 @@ mod tests {
use alloc::collections::BTreeSet;

use manul::{
dev::{run_sync_with_tracing, BinaryFormat, TestSessionParams, TestSigner},
dev::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
session::signature::Keypair,
};
use rand_core::OsRng;
use test_log::test;

use super::SimpleProtocolEntryPoint;

Expand All @@ -423,7 +424,7 @@ mod tests {
.map(|signer| (signer, SimpleProtocolEntryPoint::new(all_ids.clone())))
.collect::<Vec<_>>();

let results = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
let results = run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.results()
.unwrap();
Expand Down
5 changes: 3 additions & 2 deletions examples/src/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ mod tests {
use alloc::collections::BTreeSet;

use manul::{
dev::{run_sync_with_tracing, BinaryFormat, TestSessionParams, TestSigner},
dev::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
session::signature::Keypair,
};
use rand_core::OsRng;
use test_log::test;

use super::DoubleSimpleEntryPoint;

Expand All @@ -89,7 +90,7 @@ mod tests {
.map(|signer| (signer, DoubleSimpleEntryPoint::new(all_ids.clone())))
.collect::<Vec<_>>();

let results = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
let results = run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.results()
.unwrap();
Expand Down
9 changes: 5 additions & 4 deletions examples/src/simple_malicious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use core::fmt::Debug;

use manul::{
combinators::misbehave::{Misbehaving, MisbehavingEntryPoint},
dev::{run_sync_with_tracing, BinaryFormat, TestSessionParams, TestSigner},
dev::{run_sync, BinaryFormat, TestSessionParams, TestSigner},
protocol::{
Artifact, BoxedRound, Deserializer, DirectMessage, EntryPoint, LocalError, PartyId, ProtocolMessagePart,
RoundId, Serializer,
},
session::signature::Keypair,
};
use rand_core::{CryptoRngCore, OsRng};
use test_log::test;

use crate::simple::{Round1, Round1Message, Round2, Round2Message, SimpleProtocolEntryPoint};

Expand Down Expand Up @@ -93,7 +94,7 @@ fn serialized_garbage() {
})
.collect::<Vec<_>>();

let mut reports = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
let mut reports = run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.reports;

Expand Down Expand Up @@ -132,7 +133,7 @@ fn attributable_failure() {
})
.collect::<Vec<_>>();

let mut reports = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
let mut reports = run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.reports;

Expand Down Expand Up @@ -171,7 +172,7 @@ fn attributable_failure_round2() {
})
.collect::<Vec<_>>();

let mut reports = run_sync_with_tracing::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
let mut reports = run_sync::<_, TestSessionParams<BinaryFormat>>(&mut OsRng, entry_points)
.unwrap()
.reports;

Expand Down
4 changes: 1 addition & 3 deletions manul/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ rand = { version = "0.8", default-features = false, optional = true }
serde-persistent-deserializer = { version = "0.3", optional = true }
postcard = { version = "1", default-features = false, features = ["alloc"], optional = true }
serde_json = { version = "1", default-features = false, features = ["alloc"], optional = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"], optional = true }

[dev-dependencies]
impls = "1"
Expand All @@ -41,10 +40,9 @@ serde-persistent-deserializer = "0.3"
postcard = { version = "1", default-features = false, features = ["alloc"] }
serde_json = { version = "1", default-features = false, features = ["alloc"] }
tracing = { version = "0.1", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[features]
dev = ["rand", "postcard", "serde_json", "tracing/std", "serde-persistent-deserializer", "tracing-subscriber"]
dev = ["rand", "postcard", "serde_json", "tracing/std", "serde-persistent-deserializer"]

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 1 addition & 1 deletion manul/src/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ mod run_sync;
mod session_parameters;
mod wire_format;

pub use run_sync::{run_sync, run_sync_with_tracing};
pub use run_sync::run_sync;
pub use session_parameters::{TestHasher, TestSessionParams, TestSignature, TestSigner, TestVerifier};
pub use wire_format::{BinaryFormat, HumanReadableFormat};
20 changes: 0 additions & 20 deletions manul/src/dev/run_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use rand::Rng;
use rand_core::CryptoRngCore;
use signature::Keypair;
use tracing::debug;
use tracing_subscriber::EnvFilter;

use crate::{
protocol::{EntryPoint, Protocol},
Expand Down Expand Up @@ -89,7 +88,6 @@ where

/// Execute sessions for multiple nodes concurrently,
/// given a vector of the signer and the entry point as a tuple for each node.
#[allow(clippy::type_complexity)]
pub fn run_sync<EP, SP>(
rng: &mut impl CryptoRngCore,
entry_points: Vec<(SP::Signer, EP)>,
Expand Down Expand Up @@ -168,24 +166,6 @@ where
Ok(ExecutionResult { reports })
}

/// Same as [`run_sync()`], but enables a [`tracing`] subscriber that prints the tracing events to stdout,
/// taking options from the environment variable `RUST_LOG` (see [`mod@tracing_subscriber::fmt`] for details).
#[allow(clippy::type_complexity)]
pub fn run_sync_with_tracing<EP, SP>(
rng: &mut impl CryptoRngCore,
entry_points: Vec<(SP::Signer, EP)>,
) -> Result<ExecutionResult<EP::Protocol, SP>, LocalError>
where
EP: EntryPoint<SP::Verifier>,
SP: SessionParameters,
{
// A subscriber that prints events to stdout
let subscriber = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.finish();
tracing::subscriber::with_default(subscriber, || run_sync::<EP, SP>(rng, entry_points))
}

/// The result of a protocol execution on a set of nodes.
#[derive(Debug)]
pub struct ExecutionResult<P: Protocol, SP: SessionParameters> {
Expand Down

0 comments on commit 317d8fe

Please sign in to comment.