about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJieyou Xu <jieyouxu@outlook.com>2025-02-06 18:49:53 +0800
committerJieyou Xu <jieyouxu@outlook.com>2025-02-06 18:51:54 +0800
commit9e345fd3ed1dcd598989c8468a3ca95f0eddd345 (patch)
tree958a84b3f44861814f9e4a7993c3d51836c4f740
parentc753cb9b42e530950204dd0367525cce12811cdd (diff)
downloadrust-9e345fd3ed1dcd598989c8468a3ca95f0eddd345.tar.gz
rust-9e345fd3ed1dcd598989c8468a3ca95f0eddd345.zip
tests(std/net): remove outdated `base_port` calculation
This was never modified since `std::net` was originally introduced, when
each CI job was running multiple jobs concurrently which caused issues
with fighting over the same ports. This is not the case in the current
CI infrastructure, so remove this relic.
-rw-r--r--library/std/src/net/test.rs33
1 files changed, 3 insertions, 30 deletions
diff --git a/library/std/src/net/test.rs b/library/std/src/net/test.rs
index d318d457f35..a5c3983cd89 100644
--- a/library/std/src/net/test.rs
+++ b/library/std/src/net/test.rs
@@ -5,14 +5,15 @@ use crate::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToS
 use crate::sync::atomic::{AtomicUsize, Ordering};
 
 static PORT: AtomicUsize = AtomicUsize::new(0);
+const BASE_PORT: u16 = 19600;
 
 pub fn next_test_ip4() -> SocketAddr {
-    let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
+    let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
     SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), port))
 }
 
 pub fn next_test_ip6() -> SocketAddr {
-    let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + base_port();
+    let port = PORT.fetch_add(1, Ordering::Relaxed) as u16 + BASE_PORT;
     SocketAddr::V6(SocketAddrV6::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), port, 0, 0))
 }
 
@@ -30,31 +31,3 @@ pub fn tsa<A: ToSocketAddrs>(a: A) -> Result<Vec<SocketAddr>, String> {
         Err(e) => Err(e.to_string()),
     }
 }
-
-// The bots run multiple builds at the same time, and these builds
-// all want to use ports. This function figures out which workspace
-// it is running in and assigns a port range based on it.
-fn base_port() -> u16 {
-    let cwd = if cfg!(target_env = "sgx") {
-        String::from("sgx")
-    } else {
-        env::current_dir().unwrap().into_os_string().into_string().unwrap()
-    };
-    let dirs = [
-        "32-opt",
-        "32-nopt",
-        "musl-64-opt",
-        "cross-opt",
-        "64-opt",
-        "64-nopt",
-        "64-opt-vg",
-        "64-debug-opt",
-        "all-opt",
-        "snap3",
-        "dist",
-        "sgx",
-    ];
-    dirs.iter().enumerate().find(|&(_, dir)| cwd.contains(dir)).map(|p| p.0).unwrap_or(0) as u16
-        * 1000
-        + 19600
-}