@@ -81,7 +81,7 @@ impl Storage {
81
81
let backend = if let Some ( c) = s3:: s3_client ( ) {
82
82
StorageBackend :: S3 ( Box :: new ( S3Backend :: new ( c, metrics, config) ?) )
83
83
} else {
84
- StorageBackend :: Database ( DatabaseBackend :: new ( pool) )
84
+ StorageBackend :: Database ( DatabaseBackend :: new ( pool, metrics ) )
85
85
} ;
86
86
Ok ( Storage { backend } )
87
87
}
@@ -98,9 +98,9 @@ impl Storage {
98
98
}
99
99
100
100
#[ cfg( test) ]
101
- pub ( crate ) fn temp_new_db ( pool : Pool ) -> Result < Self , Error > {
101
+ pub ( crate ) fn temp_new_db ( pool : Pool , metrics : Arc < Metrics > ) -> Result < Self , Error > {
102
102
Ok ( Storage {
103
- backend : StorageBackend :: Database ( DatabaseBackend :: new ( pool) ) ,
103
+ backend : StorageBackend :: Database ( DatabaseBackend :: new ( pool, metrics ) ) ,
104
104
} )
105
105
}
106
106
@@ -391,7 +391,7 @@ mod backend_tests {
391
391
Ok ( ( ) )
392
392
}
393
393
394
- fn test_store_blobs ( storage : & Storage ) -> Result < ( ) , Error > {
394
+ fn test_store_blobs ( storage : & Storage , metrics : & Metrics ) -> Result < ( ) , Error > {
395
395
const NAMES : & [ & str ] = & [
396
396
"a" ,
397
397
"b" ,
@@ -419,10 +419,12 @@ mod backend_tests {
419
419
assert_eq ! ( blob. mime, actual. mime) ;
420
420
}
421
421
422
+ assert_eq ! ( NAMES . len( ) , metrics. uploaded_files_total. get( ) as usize ) ;
423
+
422
424
Ok ( ( ) )
423
425
}
424
426
425
- fn test_store_all ( storage : & Storage ) -> Result < ( ) , Error > {
427
+ fn test_store_all ( storage : & Storage , metrics : & Metrics ) -> Result < ( ) , Error > {
426
428
let dir = tempfile:: Builder :: new ( )
427
429
. prefix ( "docs.rs-upload-test" )
428
430
. tempdir ( ) ?;
@@ -464,6 +466,8 @@ mod backend_tests {
464
466
expected_algs. insert ( CompressionAlgorithm :: default ( ) ) ;
465
467
assert_eq ! ( algs, expected_algs) ;
466
468
469
+ assert_eq ! ( 2 , metrics. uploaded_files_total. get( ) ) ;
470
+
467
471
Ok ( ( ) )
468
472
}
469
473
@@ -559,7 +563,11 @@ mod backend_tests {
559
563
// Remember to add the test name to the macro below when adding a new one.
560
564
561
565
macro_rules! backend_tests {
562
- ( backends( $env: ident) { $( $backend: ident => $create: expr, ) * } tests $tests: tt ) => {
566
+ (
567
+ backends( $env: ident) { $( $backend: ident => $create: expr, ) * }
568
+ tests $tests: tt
569
+ tests_with_metrics $tests_with_metrics: tt
570
+ ) => {
563
571
$(
564
572
mod $backend {
565
573
use crate :: test:: TestEnvironment ;
@@ -571,6 +579,7 @@ mod backend_tests {
571
579
}
572
580
573
581
backend_tests!( @tests $tests) ;
582
+ backend_tests!( @tests_with_metrics $tests_with_metrics) ;
574
583
}
575
584
) *
576
585
} ;
@@ -584,6 +593,16 @@ mod backend_tests {
584
593
}
585
594
) *
586
595
} ;
596
+ ( @tests_with_metrics { $( $test: ident, ) * } ) => {
597
+ $(
598
+ #[ test]
599
+ fn $test( ) {
600
+ crate :: test:: wrapper( |env| {
601
+ super :: $test( & * get_storage( env) , & * env. metrics( ) )
602
+ } ) ;
603
+ }
604
+ ) *
605
+ } ;
587
606
}
588
607
589
608
backend_tests ! {
@@ -597,10 +616,13 @@ mod backend_tests {
597
616
test_exists,
598
617
test_get_object,
599
618
test_get_too_big,
600
- test_store_blobs,
601
- test_store_all,
602
619
test_delete_prefix,
603
620
test_delete_percent,
604
621
}
622
+
623
+ tests_with_metrics {
624
+ test_store_blobs,
625
+ test_store_all,
626
+ }
605
627
}
606
628
}
0 commit comments