Skip to content

Commit 3970ef9

Browse files
committed
Merge #169: Refactor: UDP integration tests to follow mod structure conventions
95a2cd1 refactor(udp): refactor tests to follow mod structure conventions (Jose Celano) Pull request description: Use the same dir/mod structure as in API and HTTP tracker integration tests. ACKs for top commit: josecelano: ACK 95a2cd1 Tree-SHA512: 9a7f58f12625edc002f4eb483ea21b1cf7d73bbb0871b969124005a9173b7b6a75ca3991e1a4004e90a4bb25f709d86b3eea9d225aa02a7ebcc145cc25b62a60
2 parents f860530 + 95a2cd1 commit 3970ef9

File tree

9 files changed

+378
-310
lines changed

9 files changed

+378
-310
lines changed

tests/common/fixtures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct PeerBuilder {
99
}
1010

1111
impl PeerBuilder {
12+
#[allow(dead_code)]
1213
pub fn default() -> PeerBuilder {
1314
Self {
1415
peer: default_peer_for_testing(),
@@ -44,6 +45,7 @@ impl PeerBuilder {
4445
}
4546
}
4647

48+
#[allow(dead_code)]
4749
fn default_peer_for_testing() -> Peer {
4850
Peer {
4951
peer_id: peer::Id(*b"-qB00000000000000000"),
@@ -56,6 +58,7 @@ fn default_peer_for_testing() -> Peer {
5658
}
5759
}
5860

61+
#[allow(dead_code)]
5962
pub fn invalid_info_hashes() -> Vec<String> {
6063
[
6164
"0".to_string(),

tests/common/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pub mod fixtures;
22
pub mod http;
3+
pub mod udp;

tests/common/udp.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::net::SocketAddr;
2+
use std::sync::Arc;
3+
4+
use tokio::net::UdpSocket;
5+
6+
/// A generic UDP client
7+
pub struct Client {
8+
pub socket: Arc<UdpSocket>,
9+
}
10+
11+
impl Client {
12+
#[allow(dead_code)]
13+
pub async fn connected(remote_socket_addr: &SocketAddr, local_socket_addr: &SocketAddr) -> Client {
14+
let client = Client::bind(local_socket_addr).await;
15+
client.connect(remote_socket_addr).await;
16+
client
17+
}
18+
19+
pub async fn bind(local_socket_addr: &SocketAddr) -> Self {
20+
let socket = UdpSocket::bind(local_socket_addr).await.unwrap();
21+
Self {
22+
socket: Arc::new(socket),
23+
}
24+
}
25+
26+
pub async fn connect(&self, remote_address: &SocketAddr) {
27+
self.socket.connect(remote_address).await.unwrap();
28+
}
29+
30+
#[allow(dead_code)]
31+
pub async fn send(&self, bytes: &[u8]) -> usize {
32+
self.socket.writable().await.unwrap();
33+
self.socket.send(bytes).await.unwrap()
34+
}
35+
36+
#[allow(dead_code)]
37+
pub async fn receive(&self, bytes: &mut [u8]) -> usize {
38+
self.socket.readable().await.unwrap();
39+
self.socket.recv(bytes).await.unwrap()
40+
}
41+
}

tests/udp.rs

Lines changed: 0 additions & 310 deletions
This file was deleted.

0 commit comments

Comments
 (0)