Skip to content

Commit 29eda05

Browse files
mohammadVatandoostBSteffaniakcijothomas
authored
Modify batch processor test use flush instead of sleeptime (open-telemetry#2675)
Co-authored-by: Braden Steffaniak <BradenSteffaniak+github@gmail.com> Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
1 parent 81fea07 commit 29eda05

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

opentelemetry-sdk/src/logs/batch_log_processor.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,7 @@ mod tests {
902902
)
903903
.build();
904904

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

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

opentelemetry-sdk/src/logs/log_processor_with_async_runtime.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,7 @@ mod tests {
525525
)
526526
.build();
527527

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

531530
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 5);
532531
let _ = provider.shutdown();
@@ -788,7 +787,7 @@ mod tests {
788787
KeyValue::new("k5", "v5"),
789788
]))
790789
.build();
791-
tokio::time::sleep(Duration::from_millis(500)).await; // set resource in batch log processor is not blocking. Should we make it blocking?
790+
provider.force_flush().unwrap();
792791
assert_eq!(exporter.get_resource().unwrap().into_iter().count(), 5);
793792
let _ = provider.shutdown();
794793
}

opentelemetry-sdk/src/trace/span_processor.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1240,7 +1240,6 @@ mod tests {
12401240
let config = BatchConfigBuilder::default()
12411241
.with_max_queue_size(5)
12421242
.with_max_export_batch_size(3)
1243-
.with_scheduled_delay(Duration::from_millis(50))
12441243
.build();
12451244

12461245
let processor = BatchSpanProcessor::new(exporter, config);
@@ -1250,7 +1249,7 @@ mod tests {
12501249
processor.on_end(span);
12511250
}
12521251

1253-
tokio::time::sleep(Duration::from_millis(1000)).await;
1252+
processor.force_flush().unwrap();
12541253

12551254
let exported_spans = exporter_shared.lock().unwrap();
12561255
assert_eq!(exported_spans.len(), 4);
@@ -1264,7 +1263,6 @@ mod tests {
12641263
let config = BatchConfigBuilder::default()
12651264
.with_max_queue_size(5)
12661265
.with_max_export_batch_size(3)
1267-
.with_scheduled_delay(Duration::from_millis(50))
12681266
.build();
12691267

12701268
let processor = BatchSpanProcessor::new(exporter, config);
@@ -1274,7 +1272,7 @@ mod tests {
12741272
processor.on_end(span);
12751273
}
12761274

1277-
tokio::time::sleep(Duration::from_millis(1000)).await;
1275+
processor.force_flush().unwrap();
12781276

12791277
let exported_spans = exporter_shared.lock().unwrap();
12801278
assert_eq!(exported_spans.len(), 4);
@@ -1288,7 +1286,6 @@ mod tests {
12881286
let config = BatchConfigBuilder::default()
12891287
.with_max_queue_size(20)
12901288
.with_max_export_batch_size(5)
1291-
.with_scheduled_delay(Duration::from_millis(50))
12921289
.build();
12931290

12941291
// Create the processor with the thread-safe exporter
@@ -1308,8 +1305,7 @@ mod tests {
13081305
handle.await.unwrap();
13091306
}
13101307

1311-
// Allow time for batching and export
1312-
tokio::time::sleep(Duration::from_millis(1000)).await;
1308+
processor.force_flush().unwrap();
13131309

13141310
// Verify exported spans
13151311
let exported_spans = exporter_shared.lock().unwrap();

0 commit comments

Comments
 (0)