Skip to content

Commit f399ae4

Browse files
committed
dev: check for ipv6 sockets before use in tests
1 parent d36d655 commit f399ae4

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/servers/http/v1/contract.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ mod for_all_config_modes {
6767
// Vuze (bittorrent client) docs:
6868
// https://wiki.vuze.com/w/Announce
6969

70-
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
70+
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV6};
7171
use std::str::FromStr;
7272

7373
use local_ip_address::local_ip;
7474
use reqwest::Response;
75+
use tokio::net::TcpListener;
7576
use torrust_tracker::shared::bit_torrent::info_hash::InfoHash;
7677
use torrust_tracker::tracker::peer;
7778
use torrust_tracker_test_helpers::configuration;
@@ -594,6 +595,13 @@ mod for_all_config_modes {
594595

595596
#[tokio::test]
596597
async fn should_increase_the_number_of_tcp6_connections_handled_in_statistics() {
598+
if TcpListener::bind(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0))
599+
.await
600+
.is_err()
601+
{
602+
return; // we cannot bind to a ipv6 socket, so we will skip this test
603+
}
604+
597605
let test_env = running_test_environment::<V1>(configuration::ephemeral_ipv6()).await;
598606

599607
Client::bind(*test_env.bind_address(), IpAddr::from_str("::1").unwrap())
@@ -651,6 +659,13 @@ mod for_all_config_modes {
651659

652660
#[tokio::test]
653661
async fn should_increase_the_number_of_tcp6_announce_requests_handled_in_statistics() {
662+
if TcpListener::bind(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0))
663+
.await
664+
.is_err()
665+
{
666+
return; // we cannot bind to a ipv6 socket, so we will skip this test
667+
}
668+
654669
let test_env = running_test_environment::<V1>(configuration::ephemeral_ipv6()).await;
655670

656671
Client::bind(*test_env.bind_address(), IpAddr::from_str("::1").unwrap())
@@ -830,9 +845,10 @@ mod for_all_config_modes {
830845
// Vuze (bittorrent client) docs:
831846
// https://wiki.vuze.com/w/Scrape
832847

833-
use std::net::IpAddr;
848+
use std::net::{IpAddr, Ipv6Addr, SocketAddrV6};
834849
use std::str::FromStr;
835850

851+
use tokio::net::TcpListener;
836852
use torrust_tracker::shared::bit_torrent::info_hash::InfoHash;
837853
use torrust_tracker::tracker::peer;
838854
use torrust_tracker_test_helpers::configuration;
@@ -1027,6 +1043,13 @@ mod for_all_config_modes {
10271043

10281044
#[tokio::test]
10291045
async fn should_increase_the_number_ot_tcp6_scrape_requests_handled_in_statistics() {
1046+
if TcpListener::bind(SocketAddrV6::new(Ipv6Addr::LOCALHOST, 0, 0, 0))
1047+
.await
1048+
.is_err()
1049+
{
1050+
return; // we cannot bind to a ipv6 socket, so we will skip this test
1051+
}
1052+
10301053
let test_env = running_test_environment::<V1>(configuration::ephemeral_ipv6()).await;
10311054

10321055
let info_hash = InfoHash::from_str("9c38422213e30bff212b30c360d26f9a02136422").unwrap();

0 commit comments

Comments
 (0)