M1.9: the MCP connect-failure test holds its own closed port

remote_connect_fails_fast bound a port and dropped it, so another test or
process could take the port before the connect and make it succeed. It now
holds a socket bound without listening (socket2, a test-only dependency):
connections to it are refused and nothing else can bind it meanwhile. It
also checks the failure comes within 5 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
bflatasticandClaude Opus 5.5 committed 2026-10-05 11:41:26 +07:00
1 parent 851ed15104
commit 7b30dd787b
4 files changed
+24 -2

No files matched your search

Generated
+11
View File
@@ -3549,6 +3549,16 @@ dependencies = [
"serde",
]
[[package]]
name = "socket2"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
"libc",
"windows-sys 0.61.2",
]
[[package]]
name = "spirv"
version = "0.4.0+sdk-1.4.341.0"
@@ -4194,6 +4204,7 @@ dependencies = [
"log",
"proptest",
"serde_json",
"socket2",
"vectorcraft-doc",
"vectorcraft-engine",
"vectorcraft-format",
+2
View File
@@ -38,6 +38,8 @@ serde = { version = "1", features = ["derive", "rc"] }
serde_json = { version = "1", features = ["float_roundtrip"] }
log = "0.4"
proptest = "1"
# tests: a TCP port bound without listening (connections to it are refused)
socket2 = "0.6"
# rendering / formats
vello_cpu = "0.2"
+1
View File
@@ -23,3 +23,4 @@ log = { workspace = true }
vectorcraft-testkit = { workspace = true }
proptest = { workspace = true }
image = { workspace = true }
socket2 = { workspace = true }
+10 -2
View File
@@ -377,9 +377,17 @@ fn remote_forwards_methods() {
#[test]
fn remote_connect_fails_fast() {
// Bind then drop to get a port that's (almost certainly) closed.
let port = std::net::TcpListener::bind("127.0.0.1:0").unwrap().local_addr().unwrap().port();
// A port this test holds, bound but not listening, so connecting to it is refused. (A port
// bound and dropped could be taken by another process or test before the connect.)
let held = socket2::Socket::new(socket2::Domain::IPV4, socket2::Type::STREAM, None).unwrap();
held.bind(&std::net::SocketAddr::from(([127, 0, 0, 1], 0)).into()).unwrap();
let port = held.local_addr().unwrap().as_socket().unwrap().port();
let start = std::time::Instant::now();
assert!(Remote::connect(&format!("127.0.0.1:{port}")).is_err());
assert!(start.elapsed() < std::time::Duration::from_secs(5), "took {:?}", start.elapsed());
// Nothing else could listen there meanwhile.
assert!(std::net::TcpListener::bind(format!("127.0.0.1:{port}")).is_err());
drop(held);
}
#[test]