@@ -489,4 +489,86 @@ mod tests {
489
489
490
490
assert_eq ! ( bytes. as_ref( ) , b"some data" ) ;
491
491
}
492
+
493
+ #[ tokio:: test]
494
+ async fn operation_names_include_cid_for_debugging ( ) {
495
+ use slog:: { o, Drain , Logger , Record } ;
496
+ use std:: sync:: { Arc , Mutex } ;
497
+
498
+ // Custom drain to capture log messages
499
+ struct LogCapture {
500
+ messages : Arc < Mutex < Vec < String > > > ,
501
+ }
502
+
503
+ impl Drain for LogCapture {
504
+ type Ok = ( ) ;
505
+ type Err = std:: io:: Error ;
506
+
507
+ fn log (
508
+ & self ,
509
+ record : & Record ,
510
+ _: & slog:: OwnedKVList ,
511
+ ) -> std:: result:: Result < Self :: Ok , Self :: Err > {
512
+ let message = format ! ( "{}" , record. msg( ) ) ;
513
+ self . messages . lock ( ) . unwrap ( ) . push ( message) ;
514
+ Ok ( ( ) )
515
+ }
516
+ }
517
+
518
+ let captured_messages = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
519
+ let drain = LogCapture {
520
+ messages : captured_messages. clone ( ) ,
521
+ } ;
522
+ let logger = Logger :: root ( drain. fuse ( ) , o ! ( ) ) ;
523
+
524
+ let server = mock_server ( ) . await ;
525
+ let client = Arc :: new ( IpfsGatewayClient :: new_unchecked ( server. uri ( ) , & logger) . unwrap ( ) ) ;
526
+
527
+ // Set up mock to fail twice then succeed to trigger retry with warning logs
528
+ mock_get ( )
529
+ . respond_with ( ResponseTemplate :: new ( StatusCode :: INTERNAL_SERVER_ERROR ) )
530
+ . up_to_n_times ( 2 )
531
+ . expect ( 2 )
532
+ . mount ( & server)
533
+ . await ;
534
+
535
+ mock_get ( )
536
+ . respond_with ( ResponseTemplate :: new ( StatusCode :: OK ) . set_body_bytes ( b"data" ) )
537
+ . expect ( 1 )
538
+ . mount ( & server)
539
+ . await ;
540
+
541
+ let path = make_path ( ) ;
542
+
543
+ // This should trigger retry logs because we set up failures first
544
+ let _result = client
545
+ . cat ( & path, usize:: MAX , None , RetryPolicy :: NonDeterministic )
546
+ . await
547
+ . unwrap ( ) ;
548
+
549
+ // Check that the captured log messages include the CID
550
+ let messages = captured_messages. lock ( ) . unwrap ( ) ;
551
+ let retry_messages: Vec < _ > = messages
552
+ . iter ( )
553
+ . filter ( |msg| msg. contains ( "Trying again after" ) )
554
+ . collect ( ) ;
555
+
556
+ assert ! (
557
+ !retry_messages. is_empty( ) ,
558
+ "Expected retry messages but found none. All messages: {:?}" ,
559
+ * messages
560
+ ) ;
561
+
562
+ // Verify that the operation name includes the CID
563
+ let expected_cid = "QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" ;
564
+ let has_cid_in_operation = retry_messages
565
+ . iter ( )
566
+ . any ( |msg| msg. contains ( & format ! ( "IPFS.cat[{}]" , expected_cid) ) ) ;
567
+
568
+ assert ! (
569
+ has_cid_in_operation,
570
+ "Expected operation name to include CID [{}] in retry messages: {:?}" ,
571
+ expected_cid, retry_messages
572
+ ) ;
573
+ }
492
574
}
0 commit comments