fix(harness): retry browser connection until timeout (#914)

* fix(harness): retry browser connection until timeout

* add timeout to executor shutdown

* shutdown timeout error msg

* clippy
This commit is contained in:
sinu.eth
2025-06-06 15:01:28 -07:00
committed by GitHub
parent a87125ff88
commit c128ab16ce
2 changed files with 27 additions and 9 deletions

View File

@@ -118,15 +118,26 @@ impl Executor {
format!("--user-data-dir={tmp}"),
format!("--allowed-ips=10.250.0.1"),
)
//.stderr_capture()
//.stdout_capture()
.stderr_capture()
.stdout_capture()
.start()?;
// Give the browser time to start.
tokio::time::sleep(Duration::from_millis(250)).await;
let (browser, mut handler) =
Browser::connect(format!("http://{}:{}", rpc_addr.0, PORT_BROWSER)).await?;
const TIMEOUT: usize = 10000;
const DELAY: usize = 100;
let mut retries = 0;
let (browser, mut handler) = loop {
match Browser::connect(format!("http://{}:{}", rpc_addr.0, PORT_BROWSER)).await
{
Ok(browser) => break browser,
Err(e) => {
retries += 1;
if retries * DELAY > TIMEOUT {
return Err(e.into());
}
tokio::time::sleep(Duration::from_millis(DELAY as u64)).await;
}
}
};
tokio::spawn(async move {
while let Some(res) = handler.next().await {

View File

@@ -280,8 +280,15 @@ pub async fn main() -> Result<()> {
},
}
runner.exec_p.shutdown().await?;
runner.exec_v.shutdown().await?;
// Shut down the executors before exiting.
if tokio::time::timeout(Duration::from_secs(5), async move {
_ = tokio::join!(runner.exec_p.shutdown(), runner.exec_v.shutdown());
})
.await
.is_err()
{
eprintln!("executor shutdown timed out");
}
if exit_code != 0 {
std::process::exit(exit_code);