Stabilize the mismatched executor Stop hook test (#40398)

## Why

Yielding once after spawning the test executor does not guarantee that its TCP
listener is ready, so the environment can race the server during setup.

## What changed

Poll the executor address until it accepts a TCP connection, with a five-second
timeout and a clear error if startup does not complete.

GitOrigin-RevId: b44b5bbef666a97da1299d05790f5e9c976d914f
This commit is contained in:
jif
2026-08-24 12:45:35 +00:00
committed by copyberry
parent a9e7920da1
commit 80cce09d05
+15 -2
View File
@@ -141,7 +141,8 @@ async fn executor_stop_hook_rejects_mismatched_environment() -> Result<()> {
(executor_url.to_string(), None)
} else {
let listener = TcpListener::bind("127.0.0.1:0").await?;
let executor_url = format!("ws://{}", listener.local_addr()?);
let executor_address = listener.local_addr()?;
let executor_url = format!("ws://{executor_address}");
drop(listener);
let runtime_paths = ExecServerRuntimePaths::new(
std::env::current_exe()?,
@@ -157,7 +158,19 @@ async fn executor_stop_hook_rejects_mismatched_environment() -> Result<()> {
)
.await
});
tokio::task::yield_now().await;
tokio::time::timeout(Duration::from_secs(5), async {
loop {
if tokio::net::TcpStream::connect(executor_address)
.await
.is_ok()
{
break;
}
tokio::task::yield_now().await;
}
})
.await
.context("timed out waiting for the mismatched executor to start")?;
(executor_url, Some(executor))
};