11use std:: net:: IpAddr ;
2+ use std:: sync:: Arc ;
23
34use torrust_tracker_metrics:: label:: { LabelSet , LabelValue } ;
45use torrust_tracker_metrics:: { label_name, metric_name} ;
@@ -12,7 +13,7 @@ use crate::statistics::HTTP_TRACKER_CORE_REQUESTS_RECEIVED_TOTAL;
1213///
1314/// This function panics if the client IP address is not the same as the IP
1415/// version of the event.
15- pub async fn handle_event ( event : Event , stats_repository : & Repository , now : DurationSinceUnixEpoch ) {
16+ pub async fn handle_event ( event : Event , stats_repository : & Arc < Repository > , now : DurationSinceUnixEpoch ) {
1617 match event {
1718 Event :: TcpAnnounce { connection, .. } => {
1819 // Global fixed metrics
@@ -72,6 +73,7 @@ pub async fn handle_event(event: Event, stats_repository: &Repository, now: Dura
7273#[ cfg( test) ]
7374mod tests {
7475 use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr , SocketAddr } ;
76+ use std:: sync:: Arc ;
7577
7678 use bittorrent_http_tracker_protocol:: v1:: services:: peer_ip_resolver:: { RemoteClientAddr , ResolvedIp } ;
7779 use torrust_tracker_clock:: clock:: Time ;
@@ -85,7 +87,7 @@ mod tests {
8587
8688 #[ tokio:: test]
8789 async fn should_increase_the_tcp4_announces_counter_when_it_receives_a_tcp4_announce_event ( ) {
88- let stats_repository = Repository :: new ( ) ;
90+ let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
8991 let peer = sample_peer_using_ipv4 ( ) ;
9092 let remote_client_ip = IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 2 ) ) ;
9193
@@ -110,7 +112,7 @@ mod tests {
110112
111113 #[ tokio:: test]
112114 async fn should_increase_the_tcp4_scrapes_counter_when_it_receives_a_tcp4_scrape_event ( ) {
113- let stats_repository = Repository :: new ( ) ;
115+ let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
114116
115117 handle_event (
116118 Event :: TcpScrape {
@@ -134,7 +136,7 @@ mod tests {
134136
135137 #[ tokio:: test]
136138 async fn should_increase_the_tcp6_announces_counter_when_it_receives_a_tcp6_announce_event ( ) {
137- let stats_repository = Repository :: new ( ) ;
139+ let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
138140 let peer = sample_peer_using_ipv6 ( ) ;
139141 let remote_client_ip = IpAddr :: V6 ( Ipv6Addr :: new ( 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 ) ) ;
140142
@@ -159,7 +161,7 @@ mod tests {
159161
160162 #[ tokio:: test]
161163 async fn should_increase_the_tcp6_scrapes_counter_when_it_receives_a_tcp6_scrape_event ( ) {
162- let stats_repository = Repository :: new ( ) ;
164+ let stats_repository = Arc :: new ( Repository :: new ( ) ) ;
163165
164166 handle_event (
165167 Event :: TcpScrape {
0 commit comments