mirror of
https://github.com/tlsnotary/tlsn.git
synced 2026-01-09 14:48:13 -05:00
fix(harness): improve harness stability (#962)
This commit is contained in:
@@ -26,7 +26,7 @@ pub enum Id {
|
|||||||
One,
|
One,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
|
||||||
pub enum IoMode {
|
pub enum IoMode {
|
||||||
Client,
|
Client,
|
||||||
Server,
|
Server,
|
||||||
|
|||||||
@@ -81,7 +81,11 @@ mod native {
|
|||||||
mod wasm {
|
mod wasm {
|
||||||
use super::IoProvider;
|
use super::IoProvider;
|
||||||
use crate::io::Io;
|
use crate::io::Io;
|
||||||
use anyhow::Result;
|
use anyhow::{Result, anyhow};
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
|
const CHECK_WS_OPEN_DELAY_MS: usize = 50;
|
||||||
|
const MAX_RETRIES: usize = 50;
|
||||||
|
|
||||||
impl IoProvider {
|
impl IoProvider {
|
||||||
/// Provides a connection to the server.
|
/// Provides a connection to the server.
|
||||||
@@ -107,7 +111,27 @@ mod wasm {
|
|||||||
&self.config.proto_1.0,
|
&self.config.proto_1.0,
|
||||||
self.config.proto_1.1,
|
self.config.proto_1.1,
|
||||||
);
|
);
|
||||||
let (_, io) = ws_stream_wasm::WsMeta::connect(url, None).await?;
|
let mut retries = 0;
|
||||||
|
|
||||||
|
let io = loop {
|
||||||
|
// Connect to the websocket relay.
|
||||||
|
let (_, io) = ws_stream_wasm::WsMeta::connect(url.clone(), None).await?;
|
||||||
|
|
||||||
|
// Allow some time for the relay to initiate a connection to
|
||||||
|
// the verifier.
|
||||||
|
std::thread::sleep(Duration::from_millis(CHECK_WS_OPEN_DELAY_MS as u64));
|
||||||
|
|
||||||
|
// If the relay didn't close the io, most likely the verifier
|
||||||
|
// accepted the connection.
|
||||||
|
if io.ready_state() == ws_stream_wasm::WsState::Open {
|
||||||
|
break io;
|
||||||
|
}
|
||||||
|
|
||||||
|
retries += 1;
|
||||||
|
if retries > MAX_RETRIES {
|
||||||
|
return Err(anyhow!("verifier did not accept connection"));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Ok(io.into_io())
|
Ok(io.into_io())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use chromiumoxide::{
|
|||||||
network::{EnableParams, SetCacheDisabledParams},
|
network::{EnableParams, SetCacheDisabledParams},
|
||||||
page::ReloadParams,
|
page::ReloadParams,
|
||||||
},
|
},
|
||||||
|
handler::HandlerConfig,
|
||||||
};
|
};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use harness_core::{
|
use harness_core::{
|
||||||
@@ -126,8 +127,18 @@ impl Executor {
|
|||||||
const TIMEOUT: usize = 10000;
|
const TIMEOUT: usize = 10000;
|
||||||
const DELAY: usize = 100;
|
const DELAY: usize = 100;
|
||||||
let mut retries = 0;
|
let mut retries = 0;
|
||||||
|
let config = HandlerConfig {
|
||||||
|
// Bump the timeout for long-running benches.
|
||||||
|
request_timeout: Duration::from_secs(120),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
let (browser, mut handler) = loop {
|
let (browser, mut handler) = loop {
|
||||||
match Browser::connect(format!("http://{}:{}", rpc_addr.0, PORT_BROWSER)).await
|
match Browser::connect_with_config(
|
||||||
|
format!("http://{}:{}", rpc_addr.0, PORT_BROWSER),
|
||||||
|
config.clone(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
{
|
{
|
||||||
Ok(browser) => break browser,
|
Ok(browser) => break browser,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -143,6 +154,14 @@ impl Executor {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
while let Some(res) = handler.next().await {
|
while let Some(res) = handler.next().await {
|
||||||
if let Err(e) = res {
|
if let Err(e) = res {
|
||||||
|
if e.to_string()
|
||||||
|
== "data did not match any variant of untagged enum Message"
|
||||||
|
{
|
||||||
|
// Do not log this error. It appears to be
|
||||||
|
// caused by a bug upstream.
|
||||||
|
// https://github.com/mattsse/chromiumoxide/issues/167
|
||||||
|
continue;
|
||||||
|
}
|
||||||
eprintln!("chromium error: {e:?}");
|
eprintln!("chromium error: {e:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user