Skip to content

Commit 89e5524

Browse files
BatchProcessor modified to use force_flush instead of sleep time
1 parent cf872ef commit 89e5524

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

opentelemetry-sdk/src/logs/batch_log_processor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,7 @@ mod tests {
913913
)
914914
.build();
915915

916-
// wait for the batch processor to process the resource.
917-
tokio::time::sleep(Duration::from_millis(100)).await;
916+
provider.force_flush().unwrap();
918917

919918
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 5);
920919
let _ = provider.shutdown();

opentelemetry-sdk/src/logs/log_processor_with_async_runtime.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,7 @@ mod tests {
541541
)
542542
.build();
543543

544-
// wait for the batch processor to process the resource.
545-
tokio::time::sleep(Duration::from_millis(100)).await;
544+
provider.force_flush().unwrap();
546545

547546
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 5);
548547
let _ = provider.shutdown();
@@ -804,7 +803,7 @@ mod tests {
804803
KeyValue::new("k5", "v5"),
805804
]))
806805
.build();
807-
tokio::time::sleep(Duration::from_millis(500)).await; // set resource in batch log processor is not blocking. Should we make it blocking?
806+
provider.force_flush().unwrap();
808807
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 5);
809808
let _ = provider.shutdown();
810809
}

opentelemetry-sdk/src/trace/span_processor.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,7 +1268,7 @@ mod tests {
12681268
processor.on_end(span);
12691269
}
12701270

1271-
tokio::time::sleep(Duration::from_millis(1000)).await;
1271+
processor.force_flush().unwrap();
12721272

12731273
let exported_spans = exporter_shared.lock().unwrap();
12741274
assert_eq!(exported_spans.len(), 4);
@@ -1292,7 +1292,7 @@ mod tests {
12921292
processor.on_end(span);
12931293
}
12941294

1295-
tokio::time::sleep(Duration::from_millis(1000)).await;
1295+
processor.force_flush().unwrap();
12961296

12971297
let exported_spans = exporter_shared.lock().unwrap();
12981298
assert_eq!(exported_spans.len(), 4);
@@ -1326,8 +1326,7 @@ mod tests {
13261326
handle.await.unwrap();
13271327
}
13281328

1329-
// Allow time for batching and export
1330-
tokio::time::sleep(Duration::from_millis(1000)).await;
1329+
processor.force_flush().unwrap();
13311330

13321331
// Verify exported spans
13331332
let exported_spans = exporter_shared.lock().unwrap();

0 commit comments

Comments
 (0)