@@ -412,7 +412,7 @@ impl BaggageExt for Context {
412
412
}
413
413
414
414
fn with_cleared_baggage ( & self ) -> Self {
415
- self . with_value ( Baggage :: new ( ) )
415
+ self . with_baggage ( Baggage :: new ( ) )
416
416
}
417
417
418
418
fn baggage ( & self ) -> & Baggage {
@@ -653,4 +653,28 @@ mod tests {
653
653
baggage. insert ( "(example)" , "1" ) ;
654
654
assert ! ( baggage. is_empty( ) ) ;
655
655
}
656
+
657
+ #[ test]
658
+ fn test_context_clear_baggage ( ) {
659
+ let ctx = Context :: new ( ) ;
660
+ let ctx = ctx. with_baggage ( [ KeyValue :: new ( "foo" , 1 ) ] ) ;
661
+ let _guard = ctx. attach ( ) ;
662
+
663
+ {
664
+ let ctx = Context :: current ( ) ;
665
+ let baggage = ctx. baggage ( ) ;
666
+ // At this point baggage should still contain the inital value.
667
+ assert_eq ! ( baggage. len( ) , 1 ) ;
668
+
669
+ // Baggage gets cleared.
670
+ let ctx = ctx. with_cleared_baggage ( ) ;
671
+ let _guard = ctx. attach ( ) ;
672
+ {
673
+ let ctx = Context :: current ( ) ;
674
+ let baggage = ctx. baggage ( ) ;
675
+ // Baggage should contain no entries.
676
+ assert_eq ! ( baggage. len( ) , 0 ) ;
677
+ }
678
+ }
679
+ }
656
680
}
0 commit comments