Skip to content

Commit 052c20d

Browse files
committed
add more tests
1 parent 7ccc90e commit 052c20d

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

opentelemetry-sdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ rustdoc-args = ["--cfg", "docsrs"]
3737
[dev-dependencies]
3838
criterion = { workspace = true, features = ["html_reports"] }
3939
temp-env = { workspace = true }
40+
num_cpus = "1.15.0"
4041

4142
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
4243
pprof = { version = "0.13", features = ["flamegraph", "criterion"] }

opentelemetry-sdk/src/logs/log_processor.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ mod tests {
555555
use opentelemetry::{logs::LogResult, KeyValue};
556556
use std::sync::{Arc, Mutex};
557557
use std::time::Duration;
558+
//use num_cpus;
558559

559560
#[derive(Debug, Clone)]
560561
struct MockLogExporter {
@@ -1159,16 +1160,21 @@ mod tests {
11591160
assert_eq!(exporter.len().await, 1);
11601161
}
11611162

1162-
#[tokio::test(flavor = "multi_thread")]
1163-
async fn test_simple_processor_async_exporter_with_multi_thread_runtime() {
1163+
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
1164+
#[ignore]
1165+
// all threads are blocked running blocked::export(), and the exporter further needs tokio
1166+
// runtime to progress on this blocked thread, resulting in deadlock.
1167+
async fn test_simple_processor_async_exporter_with_multi_thread_runtime_all_cores_blocked() {
11641168
let exporter = LogExporterThatRequiresTokioSpawn::new();
11651169
let processor = Arc::new(Mutex::new(SimpleLogProcessor::new(Box::new(
11661170
exporter.clone(),
11671171
))));
11681172

1173+
let concurrent_emit = 5; // number of worker sthreads + 1
1174+
11691175
let mut handles = vec![];
1170-
// send 4 events concurrently
1171-
for _ in 0..4 {
1176+
// send 2 events concurrently
1177+
for _ in 0..concurrent_emit {
11721178
let processor_clone = Arc::clone(&processor);
11731179
let handle = tokio::spawn(async move {
11741180
let mut record: LogRecord = Default::default();
@@ -1184,7 +1190,21 @@ mod tests {
11841190
for handle in handles {
11851191
handle.await.unwrap();
11861192
}
1187-
assert_eq!(exporter.len().await, 4);
1193+
assert_eq!(exporter.len().await, 2);
1194+
}
1195+
1196+
#[tokio::test(flavor = "multi_thread")]
1197+
async fn test_simple_processor_async_exporter_with_multi_thread_runtime() {
1198+
let exporter = LogExporterThatRequiresTokioSpawn::new();
1199+
1200+
let processor = SimpleLogProcessor::new(Box::new(exporter.clone()));
1201+
1202+
let mut record: LogRecord = Default::default();
1203+
let instrumentation: InstrumentationLibrary = Default::default();
1204+
1205+
processor.emit(&mut record, &instrumentation);
1206+
1207+
assert_eq!(exporter.len().await, 1);
11881208
}
11891209

11901210
#[tokio::test(flavor = "current_thread")]

0 commit comments

Comments
 (0)