mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-01-09 14:48:13 -05:00
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:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user