forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.rs
More file actions
123 lines (87 loc) · 3.87 KB
/
Copy pathhandler.rs
File metadata and controls
123 lines (87 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
use crate::statistics::event::Event;
use crate::statistics::repository::Repository;
pub async fn handle_event(event: Event, stats_repository: &Repository) {
match event {
// TCP4
Event::Tcp4Announce => {
stats_repository.increase_tcp4_announces().await;
stats_repository.increase_tcp4_connections().await;
}
Event::Tcp4Scrape => {
stats_repository.increase_tcp4_scrapes().await;
stats_repository.increase_tcp4_connections().await;
}
// TCP6
Event::Tcp6Announce => {
stats_repository.increase_tcp6_announces().await;
stats_repository.increase_tcp6_connections().await;
}
Event::Tcp6Scrape => {
stats_repository.increase_tcp6_scrapes().await;
stats_repository.increase_tcp6_connections().await;
}
}
tracing::debug!("stats: {:?}", stats_repository.get_stats().await);
}
#[cfg(test)]
mod tests {
use crate::statistics::event::handler::handle_event;
use crate::statistics::event::Event;
use crate::statistics::repository::Repository;
#[tokio::test]
async fn should_increase_the_tcp4_announces_counter_when_it_receives_a_tcp4_announce_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp4Announce, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp4_announces_handled, 1);
}
#[tokio::test]
async fn should_increase_the_tcp4_connections_counter_when_it_receives_a_tcp4_announce_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp4Announce, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp4_connections_handled, 1);
}
#[tokio::test]
async fn should_increase_the_tcp4_scrapes_counter_when_it_receives_a_tcp4_scrape_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp4Scrape, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp4_scrapes_handled, 1);
}
#[tokio::test]
async fn should_increase_the_tcp4_connections_counter_when_it_receives_a_tcp4_scrape_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp4Scrape, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp4_connections_handled, 1);
}
#[tokio::test]
async fn should_increase_the_tcp6_announces_counter_when_it_receives_a_tcp6_announce_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp6Announce, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp6_announces_handled, 1);
}
#[tokio::test]
async fn should_increase_the_tcp6_connections_counter_when_it_receives_a_tcp6_announce_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp6Announce, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp6_connections_handled, 1);
}
#[tokio::test]
async fn should_increase_the_tcp6_scrapes_counter_when_it_receives_a_tcp6_scrape_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp6Scrape, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp6_scrapes_handled, 1);
}
#[tokio::test]
async fn should_increase_the_tcp6_connections_counter_when_it_receives_a_tcp6_scrape_event() {
let stats_repository = Repository::new();
handle_event(Event::Tcp6Scrape, &stats_repository).await;
let stats = stats_repository.get_stats().await;
assert_eq!(stats.tcp6_connections_handled, 1);
}
}