diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-07 21:31:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-07 21:31:03 +0100 |
| commit | 353650332d839532785bb9fb3a73265c0238acee (patch) | |
| tree | 827c619c70d3f5521a74290d4f498c5d3cf7d570 | |
| parent | ca56709e783bae2a949398c84ad7850d3928e7e0 (diff) | |
| parent | 9e345fd3ed1dcd598989c8468a3ca95f0eddd345 (diff) | |
| download | rust-353650332d839532785bb9fb3a73265c0238acee.tar.gz rust-353650332d839532785bb9fb3a73265c0238acee.zip | |
Rollup merge of #136635 - jieyouxu:base_port, r=joboet
Remove outdated `base_port` calculation in std net test This was never modified since `std::net` was originally introduced in 395709ca6d39ba1e095e404e1d2a169d918b7f0c, when at that time, each CI runner was running multiple jobs concurrently. This seems to have originally caused issues with jobs fighting over the same ports. This is not the case in the current CI infrastructure, so remove this relic in favor of a simple constant base port number. I double-checked `19600` and nearby port numbers, and this isn't a well-known port number AFAICT[^1]. Closes #136633. [^1]: At the time of writing.
| -rw-r--r-- | library/std/src/net/test.rs | 33 |
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 -} |
