@@ -520,19 +520,36 @@ mod tests {
520
520
thread:: sleep ( std:: time:: Duration :: from_millis ( 10 ) ) ;
521
521
}
522
522
523
- // shutdown logger provider explicitly call shutdown on the logger
523
+ // Intentionally *not* calling shutdown/flush on the provider, but
524
+ // instead relying on shutdown_logger_provider which causes the global
525
+ // provider to be dropped, leading to the sdk logger provider's drop to
526
+ // be called, which is expected to call shutdown on processors.
524
527
shutdown_logger_provider ( ) ;
525
528
526
529
// Assert
527
530
528
- // shutdown_logger_provider should be shutdown regardless if the logger is dropped.
529
- assert ! ( * shutdown_called. lock( ) . unwrap( ) ) ;
531
+ // shutdown_logger_provider is necessary but not sufficient, as loggers
532
+ // hold on to the the provider (via inner provider clones).
533
+ assert ! ( !* shutdown_called. lock( ) . unwrap( ) ) ;
530
534
531
535
// flush is never called by the sdk.
532
536
assert ! ( !* flush_called. lock( ) . unwrap( ) ) ;
533
537
538
+ // Drop one of the logger. Not enough!
539
+ drop ( logger1) ;
540
+ assert ! ( !* shutdown_called. lock( ) . unwrap( ) ) ;
541
+
542
+ // drop logger2, which is the only remaining logger in this thread.
543
+ // Still not enough!
544
+ drop ( logger2) ;
545
+ assert ! ( !* shutdown_called. lock( ) . unwrap( ) ) ;
546
+
547
+ // now signal the spawned thread to end, which causes it to drop its
548
+ // logger. Since that is the last logger, the provider (inner provider)
549
+ // is finally dropped, triggering shutdown
534
550
* signal_to_end. lock ( ) . unwrap ( ) = true ;
535
551
handle. join ( ) . unwrap ( ) ;
552
+ assert ! ( * shutdown_called. lock( ) . unwrap( ) ) ;
536
553
537
554
// flush is never called by the sdk.
538
555
assert ! ( !* flush_called. lock( ) . unwrap( ) ) ;
0 commit comments