Skip to content

Commit

Permalink
[Add][Test] Linting
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Van de Vyver <[email protected]>
  • Loading branch information
taqtiqa-mark committed Sep 13, 2023
1 parent 01bdf8a commit 23422fb
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 73 deletions.
4 changes: 3 additions & 1 deletion examples/unit_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ mod test_util {
use super::*;

pub fn setup_minitrace<F>(test: F)
where F: FnOnce() -> Result<()> + 'static {
where
F: FnOnce() -> Result<()> + 'static,
{
minitrace::set_reporter(ConsoleReporter, Config::default());
{
let root = Span::root(closure_name::<F>(), SpanContext::random());
Expand Down
9 changes: 5 additions & 4 deletions minitrace-tests/integration/tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// - `dev`: Generate all missing `*.expanded.rs` files, and flag changes.
// - `ci`: Generate nothing, and fail on mismatches.
//
use crate::tests::*; //IntegrationTest;
use super::IntegrationTest;
use crate::tests::*; //IntegrationTest;

inventory::submit!(IntegrationTest {
name: "indev",
Expand All @@ -25,11 +25,12 @@ pub fn indev() {
macrotest::expand_args(
src,
&[
"--features", "minitrace-tests/default minitrace-tests/as",
"--features",
"minitrace-tests/default minitrace-tests/as",
"--manifest-path",
"./Cargo.toml",
],
);
],
);
#[cfg(feature = "tk")]
macrotest::expand_args(
src,
Expand Down
12 changes: 4 additions & 8 deletions src/collector/global_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,10 @@ impl GlobalCollector {

std::thread::Builder::new()
.name("minitrace-global-collector".to_string())
.spawn(move || {
loop {
let begin_instant = std::time::Instant::now();
GLOBAL_COLLECTOR.lock().handle_commands(false);
std::thread::sleep(
COLLECT_LOOP_INTERVAL.saturating_sub(begin_instant.elapsed()),
);
}
.spawn(move || loop {
let begin_instant = std::time::Instant::now();
GLOBAL_COLLECTOR.lock().handle_commands(false);
std::thread::sleep(COLLECT_LOOP_INTERVAL.saturating_sub(begin_instant.elapsed()));
})
.unwrap();

Expand Down
4 changes: 3 additions & 1 deletion src/local/local_span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl LocalSpan {
/// ```
#[inline]
pub fn with_property<F>(self, property: F) -> Self
where F: FnOnce() -> (Cow<'static, str>, Cow<'static, str>) {
where
F: FnOnce() -> (Cow<'static, str>, Cow<'static, str>),
{
self.with_properties(|| [property()])
}

Expand Down
31 changes: 17 additions & 14 deletions src/local/local_span_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,23 @@ span1 []
let span = span_line.start_span("span").unwrap();
let current_token = span_line.current_collect_token().unwrap();
assert_eq!(current_token.len(), 2);
assert_eq!(current_token.as_slice(), &[
CollectTokenItem {
trace_id: TraceId(1234),
parent_id: span_line.span_queue.current_span_id().unwrap(),
collect_id: 42,
is_root: false,
},
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: span_line.span_queue.current_span_id().unwrap(),
collect_id: 43,
is_root: false,
}
]);
assert_eq!(
current_token.as_slice(),
&[
CollectTokenItem {
trace_id: TraceId(1234),
parent_id: span_line.span_queue.current_span_id().unwrap(),
collect_id: 42,
is_root: false,
},
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: span_line.span_queue.current_span_id().unwrap(),
collect_id: 43,
is_root: false,
}
]
);
span_line.finish_span(span);

let current_token = span_line.current_collect_token().unwrap();
Expand Down
76 changes: 38 additions & 38 deletions src/local/local_span_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,39 +217,35 @@ span1 []
{
let span_line4 = span_stack.register_span_line(None).unwrap();
{
assert!(
span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: SpanId::default(),
collect_id: 43,
is_root: false,
}
.into()
))
.is_none()
);
assert!(span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1235),
parent_id: SpanId::default(),
collect_id: 43,
is_root: false,
}
.into()
))
.is_none());
assert!(span_stack.register_span_line(None).is_none());
}
let _ = span_stack.unregister_and_collect(span_line4).unwrap();
}
{
let span_line5 = span_stack.register_span_line(None).unwrap();
{
assert!(
span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1236),
parent_id: SpanId::default(),
collect_id: 44,
is_root: false,
}
.into()
))
.is_none()
);
assert!(span_stack
.register_span_line(Some(
CollectTokenItem {
trace_id: TraceId(1236),
parent_id: SpanId::default(),
collect_id: 44,
is_root: false,
}
.into()
))
.is_none());
assert!(span_stack.register_span_line(None).is_none());
}
let _ = span_stack.unregister_and_collect(span_line5).unwrap();
Expand All @@ -272,9 +268,10 @@ span1 []
is_root: false,
};
let span_line1 = span_stack.register_span_line(Some(token1.into())).unwrap();
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token1
]);
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token1]
);
{
let span_line2 = span_stack.register_span_line(None).unwrap();
assert!(span_stack.current_collect_token().is_none());
Expand All @@ -286,9 +283,10 @@ span1 []
is_root: false,
};
let span_line3 = span_stack.register_span_line(Some(token3.into())).unwrap();
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token3
]);
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token3]
);
let _ = span_stack.unregister_and_collect(span_line3).unwrap();
}
assert!(span_stack.current_collect_token().is_none());
Expand All @@ -301,14 +299,16 @@ span1 []
is_root: false,
};
let span_line4 = span_stack.register_span_line(Some(token4.into())).unwrap();
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token4
]);
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token4]
);
let _ = span_stack.unregister_and_collect(span_line4).unwrap();
}
assert_eq!(span_stack.current_collect_token().unwrap().as_slice(), &[
token1
]);
assert_eq!(
span_stack.current_collect_token().unwrap().as_slice(),
&[token1]
);
let _ = span_stack.unregister_and_collect(span_line1).unwrap();
assert!(span_stack.current_collect_token().is_none());
}
Expand Down
8 changes: 4 additions & 4 deletions src/local/span_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ span1 []
let mut queue = SpanQueue::with_capacity(16);
{
let span1 = queue.start_span("span1").unwrap();
queue.add_properties(&span1, [
("k1".into(), "v1".into()),
("k2".into(), "v2".into()),
]);
queue.add_properties(
&span1,
[("k1".into(), "v1".into()), ("k2".into(), "v2".into())],
);
{
let span2 = queue.start_span("span2").unwrap();
queue.add_properties(&span2, [("k1".into(), "v1".into())]);
Expand Down
4 changes: 3 additions & 1 deletion src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ impl Span {
/// ```
#[inline]
pub fn with_property<F>(self, property: F) -> Self
where F: FnOnce() -> (Cow<'static, str>, Cow<'static, str>) {
where
F: FnOnce() -> (Cow<'static, str>, Cow<'static, str>),
{
self.with_properties(move || [property()])
}

Expand Down
6 changes: 4 additions & 2 deletions src/util/object_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,17 @@ impl<'a, T> Reusable<'a, T> {
}

impl<'a, T> std::fmt::Debug for Reusable<'a, T>
where T: std::fmt::Debug
where
T: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.obj.fmt(f)
}
}

impl<'a, T> std::cmp::PartialEq for Reusable<'a, T>
where T: std::cmp::PartialEq
where
T: std::cmp::PartialEq,
{
fn eq(&self, other: &Self) -> bool {
T::eq(self, other)
Expand Down

0 comments on commit 23422fb

Please sign in to comment.