1
- use crate :: statistics:: event:: { Event , UdpResponseKind } ;
1
+ use crate :: statistics:: event:: Event ;
2
2
use crate :: statistics:: repository:: Repository ;
3
3
4
4
pub async fn handle_event ( event : Event , stats_repository : & Repository ) {
5
5
match event {
6
- // UDP
7
- Event :: UdpRequestAborted => {
8
- stats_repository. increase_udp_requests_aborted ( ) . await ;
9
- }
10
- Event :: UdpRequestBanned => {
11
- stats_repository. increase_udp_requests_banned ( ) . await ;
12
- }
13
-
14
6
// UDP4
15
- Event :: Udp4Request => {
16
- stats_repository. increase_udp4_requests ( ) . await ;
17
- }
18
7
Event :: Udp4Connect => {
19
8
stats_repository. increase_udp4_connections ( ) . await ;
20
9
}
@@ -24,39 +13,8 @@ pub async fn handle_event(event: Event, stats_repository: &Repository) {
24
13
Event :: Udp4Scrape => {
25
14
stats_repository. increase_udp4_scrapes ( ) . await ;
26
15
}
27
- Event :: Udp4Response {
28
- kind,
29
- req_processing_time,
30
- } => {
31
- stats_repository. increase_udp4_responses ( ) . await ;
32
-
33
- match kind {
34
- UdpResponseKind :: Connect => {
35
- stats_repository
36
- . recalculate_udp_avg_connect_processing_time_ns ( req_processing_time)
37
- . await ;
38
- }
39
- UdpResponseKind :: Announce => {
40
- stats_repository
41
- . recalculate_udp_avg_announce_processing_time_ns ( req_processing_time)
42
- . await ;
43
- }
44
- UdpResponseKind :: Scrape => {
45
- stats_repository
46
- . recalculate_udp_avg_scrape_processing_time_ns ( req_processing_time)
47
- . await ;
48
- }
49
- UdpResponseKind :: Error => { }
50
- }
51
- }
52
- Event :: Udp4Error => {
53
- stats_repository. increase_udp4_errors ( ) . await ;
54
- }
55
16
56
17
// UDP6
57
- Event :: Udp6Request => {
58
- stats_repository. increase_udp6_requests ( ) . await ;
59
- }
60
18
Event :: Udp6Connect => {
61
19
stats_repository. increase_udp6_connections ( ) . await ;
62
20
}
@@ -66,15 +24,6 @@ pub async fn handle_event(event: Event, stats_repository: &Repository) {
66
24
Event :: Udp6Scrape => {
67
25
stats_repository. increase_udp6_scrapes ( ) . await ;
68
26
}
69
- Event :: Udp6Response {
70
- kind : _,
71
- req_processing_time : _,
72
- } => {
73
- stats_repository. increase_udp6_responses ( ) . await ;
74
- }
75
- Event :: Udp6Error => {
76
- stats_repository. increase_udp6_errors ( ) . await ;
77
- }
78
27
}
79
28
80
29
tracing:: debug!( "stats: {:?}" , stats_repository. get_stats( ) . await ) ;
@@ -151,100 +100,4 @@ mod tests {
151
100
152
101
assert_eq ! ( stats. udp6_scrapes_handled, 1 ) ;
153
102
}
154
-
155
- #[ tokio:: test]
156
- async fn should_increase_the_udp_abort_counter_when_it_receives_a_udp_abort_event ( ) {
157
- let stats_repository = Repository :: new ( ) ;
158
-
159
- handle_event ( Event :: UdpRequestAborted , & stats_repository) . await ;
160
- let stats = stats_repository. get_stats ( ) . await ;
161
- assert_eq ! ( stats. udp_requests_aborted, 1 ) ;
162
- }
163
- #[ tokio:: test]
164
- async fn should_increase_the_udp_ban_counter_when_it_receives_a_udp_banned_event ( ) {
165
- let stats_repository = Repository :: new ( ) ;
166
-
167
- handle_event ( Event :: UdpRequestBanned , & stats_repository) . await ;
168
- let stats = stats_repository. get_stats ( ) . await ;
169
- assert_eq ! ( stats. udp_requests_banned, 1 ) ;
170
- }
171
-
172
- #[ tokio:: test]
173
- async fn should_increase_the_udp4_requests_counter_when_it_receives_a_udp4_request_event ( ) {
174
- let stats_repository = Repository :: new ( ) ;
175
-
176
- handle_event ( Event :: Udp4Request , & stats_repository) . await ;
177
-
178
- let stats = stats_repository. get_stats ( ) . await ;
179
-
180
- assert_eq ! ( stats. udp4_requests, 1 ) ;
181
- }
182
-
183
- #[ tokio:: test]
184
- async fn should_increase_the_udp4_responses_counter_when_it_receives_a_udp4_response_event ( ) {
185
- let stats_repository = Repository :: new ( ) ;
186
-
187
- handle_event (
188
- Event :: Udp4Response {
189
- kind : crate :: statistics:: event:: UdpResponseKind :: Announce ,
190
- req_processing_time : std:: time:: Duration :: from_secs ( 1 ) ,
191
- } ,
192
- & stats_repository,
193
- )
194
- . await ;
195
-
196
- let stats = stats_repository. get_stats ( ) . await ;
197
-
198
- assert_eq ! ( stats. udp4_responses, 1 ) ;
199
- }
200
-
201
- #[ tokio:: test]
202
- async fn should_increase_the_udp4_errors_counter_when_it_receives_a_udp4_error_event ( ) {
203
- let stats_repository = Repository :: new ( ) ;
204
-
205
- handle_event ( Event :: Udp4Error , & stats_repository) . await ;
206
-
207
- let stats = stats_repository. get_stats ( ) . await ;
208
-
209
- assert_eq ! ( stats. udp4_errors_handled, 1 ) ;
210
- }
211
-
212
- #[ tokio:: test]
213
- async fn should_increase_the_udp6_requests_counter_when_it_receives_a_udp6_request_event ( ) {
214
- let stats_repository = Repository :: new ( ) ;
215
-
216
- handle_event ( Event :: Udp6Request , & stats_repository) . await ;
217
-
218
- let stats = stats_repository. get_stats ( ) . await ;
219
-
220
- assert_eq ! ( stats. udp6_requests, 1 ) ;
221
- }
222
-
223
- #[ tokio:: test]
224
- async fn should_increase_the_udp6_response_counter_when_it_receives_a_udp6_response_event ( ) {
225
- let stats_repository = Repository :: new ( ) ;
226
-
227
- handle_event (
228
- Event :: Udp6Response {
229
- kind : crate :: statistics:: event:: UdpResponseKind :: Announce ,
230
- req_processing_time : std:: time:: Duration :: from_secs ( 1 ) ,
231
- } ,
232
- & stats_repository,
233
- )
234
- . await ;
235
-
236
- let stats = stats_repository. get_stats ( ) . await ;
237
-
238
- assert_eq ! ( stats. udp6_responses, 1 ) ;
239
- }
240
- #[ tokio:: test]
241
- async fn should_increase_the_udp6_errors_counter_when_it_receives_a_udp6_error_event ( ) {
242
- let stats_repository = Repository :: new ( ) ;
243
-
244
- handle_event ( Event :: Udp6Error , & stats_repository) . await ;
245
-
246
- let stats = stats_repository. get_stats ( ) . await ;
247
-
248
- assert_eq ! ( stats. udp6_errors_handled, 1 ) ;
249
- }
250
103
}
0 commit comments