@@ -5,11 +5,15 @@ use aquatic_udp_protocol::AnnounceEvent;
55use bittorrent_primitives:: info_hash:: InfoHash ;
66use bittorrent_tracker_core:: announce_handler:: PeersWanted ;
77use bittorrent_tracker_core:: container:: TrackerCoreContainer ;
8+ use bittorrent_tracker_core:: statistics:: persisted_metrics:: load_persisted_metrics;
89use tokio:: task:: yield_now;
910use torrust_tracker_configuration:: Core ;
11+ use torrust_tracker_metrics:: label:: LabelSet ;
12+ use torrust_tracker_metrics:: metric:: MetricName ;
1013use torrust_tracker_primitives:: core:: { AnnounceData , ScrapeData } ;
1114use torrust_tracker_primitives:: peer:: Peer ;
1215use torrust_tracker_primitives:: swarm_metadata:: SwarmMetadata ;
16+ use torrust_tracker_primitives:: DurationSinceUnixEpoch ;
1317use torrust_tracker_torrent_repository:: container:: TorrentRepositoryContainer ;
1418
1519pub struct TestEnv {
@@ -45,6 +49,22 @@ impl TestEnv {
4549 }
4650
4751 pub async fn start ( & self ) {
52+ let now = DurationSinceUnixEpoch :: from_secs ( 0 ) ;
53+ self . load_persisted_metrics ( now) . await ;
54+ self . run_jobs ( ) . await ;
55+ }
56+
57+ async fn load_persisted_metrics ( & self , now : DurationSinceUnixEpoch ) {
58+ load_persisted_metrics (
59+ & self . tracker_core_container . stats_repository ,
60+ & self . tracker_core_container . db_torrent_repository ,
61+ now,
62+ )
63+ . await
64+ . unwrap ( ) ;
65+ }
66+
67+ async fn run_jobs ( & self ) {
4868 let mut jobs = vec ! [ ] ;
4969
5070 let job = torrust_tracker_torrent_repository:: statistics:: event:: listener:: run_event_listener (
@@ -135,4 +155,15 @@ impl TestEnv {
135155 pub async fn remove_swarm ( & self , info_hash : & InfoHash ) {
136156 self . torrent_repository_container . swarms . remove ( info_hash) . await . unwrap ( ) ;
137157 }
158+
159+ pub async fn get_counter_value ( & self , metric_name : & str ) -> u64 {
160+ self . tracker_core_container
161+ . stats_repository
162+ . get_metrics ( )
163+ . await
164+ . metric_collection
165+ . get_counter_value ( & MetricName :: new ( metric_name) , & LabelSet :: default ( ) )
166+ . unwrap ( )
167+ . value ( )
168+ }
138169}
0 commit comments