Skip to content

Commit

Permalink
test: fix multi threads unstable tests (#215)
Browse files Browse the repository at this point in the history
* test: fix multi threads unstable tests

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>

* chore: add new contributors

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>

---------

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
  • Loading branch information
zhongzc committed May 6, 2024
1 parent 9dc5c99 commit b987f64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ Jiang Yinzuo
Jonathan Chuang
Lewis Hallam
Mark Van de Vyver
morristai
piercetrey-figure
Renkai Ge
rrichardson
Stephen Cirner
shota kizawa
TennyZhuang
Expand Down
15 changes: 13 additions & 2 deletions minitrace/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,20 @@ fn multiple_threads_single_span() {
let root = Span::root("root", SpanContext::random());
let _g = root.set_local_parent();

let mut handles = vec![];

for _ in 0..4 {
let child_span = Span::enter_with_local_parent("cross-thread");
scope.spawn(move |_| {
let h = scope.spawn(move |_| {
let _g = child_span.set_local_parent();
four_spans();
});
handles.push(h);
}

four_spans();

handles.into_iter().for_each(|h| h.join().unwrap());
})
.unwrap();

Expand Down Expand Up @@ -212,22 +217,28 @@ fn multiple_threads_multiple_spans() {
let root2 = Span::root("root2", SpanContext::new(TraceId(13), SpanId::default()));
let local_collector = LocalCollector::start();

let mut handles = vec![];

for _ in 0..4 {
let merged = Span::enter_with_parents("merged", vec![&root1, &root2]);
let _g = merged.set_local_parent();
let _local = LocalSpan::enter_with_local_parent("local");
scope.spawn(move |_| {
let h = scope.spawn(move |_| {
let local_collector = LocalCollector::start();

four_spans();

let local_spans = local_collector.collect();
merged.push_child_spans(local_spans);
});

handles.push(h);
}

four_spans();

handles.into_iter().for_each(|h| h.join().unwrap());

let local_spans = local_collector.collect();
root1.push_child_spans(local_spans.clone());
root2.push_child_spans(local_spans);
Expand Down

0 comments on commit b987f64

Please sign in to comment.