Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONTAINER?=testrpc
IMAGE?=testrpc
IMAGE?=spacecomp/testrpc:latest

build:
@cargo build --bin testrpc
Expand Down
2 changes: 2 additions & 0 deletions src/adapters/hotshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ impl Adapter for HotshotAdapter {
_iteration: u32,
num_txs: usize,
tx_size: usize,
timeout: Option<std::time::Duration>,
) -> Result<RoundResults, TestrpcError> {
let mut txs: Vec<String> = Vec::new();
for _ in 0..num_txs {
Expand All @@ -106,6 +107,7 @@ impl Adapter for HotshotAdapter {
req_id,
RPC_METHOD,
serde_json::json!({ "txs": txs }),
timeout,
)
.await?;

Expand Down
1 change: 1 addition & 0 deletions src/adapters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub trait Adapter {
iteration: u32,
num_txs: usize,
tx_size: usize,
timeout: Option<std::time::Duration>,
) -> impl std::future::Future<Output = Result<common::RoundResults, common::TestrpcError>> + Send;
}

Expand Down
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ pub struct Config {
pub rpcs: Option<Vec<String>>,
/// Rounds declaration
pub rounds: Vec<Round>,
/// Timeout for each RPC request in seconds
/// If None, defaults to 15 seconds
pub timeout: Option<u32>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
6 changes: 5 additions & 1 deletion src/jrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub async fn send(
req_id: u64,
method: &str,
params: Value,
timeout: Option<std::time::Duration>,
) -> Result<RpcResponse, TestrpcError> {
let rpc_request = RpcRequest {
jsonrpc: "2.0".to_string(),
Expand All @@ -64,7 +65,10 @@ pub async fn send(
if env::var("DRY_RUN").is_ok() {
return send_noop(rpc_url, rpc_request).await;
}
let client = reqwest::Client::new();
let client = reqwest::ClientBuilder::new()
.timeout(timeout.unwrap_or(std::time::Duration::from_secs(15)))
.build()
.map_err(|e| TestrpcError::RpcError(format!("Failed to build client: {e}")))?;

let start_time = std::time::Instant::now();

Expand Down
6 changes: 5 additions & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ pub async fn run(
let iteration = i;
let round_num = r;
let adapter = cfg.adapter.clone();
let timeout = cfg.timeout.map(|t| Duration::from_secs(t as u64));
tokio::select! {
_ = task::spawn(async move {
match process_round(adapter, round, iteration, rpc_urls, round_templates).await {
match process_round(adapter, round, iteration, rpc_urls, round_templates, timeout).await {
Ok(result) => {
tracing::debug!("Iteration {} round {} completed", iteration, round_num);
let mut results = results.write().unwrap();
Expand Down Expand Up @@ -91,6 +92,7 @@ async fn process_round(
iteration: u32,
rpc_urls: Vec<String>,
round_templates: HashMap<String, config::RoundTemplate>,
timeout: Option<std::time::Duration>,
) -> Result<RoundResults, TestrpcError> {
let mut req_id = iteration as u64;
let mut results = RoundResults { sent: 0, failed: 0 };
Expand Down Expand Up @@ -120,6 +122,7 @@ async fn process_round(
iteration,
template.txs,
template.tx_size,
timeout,
)
.await
});
Expand Down Expand Up @@ -172,6 +175,7 @@ mod tests {
0,
rpc_urls,
round_templates,
Some(std::time::Duration::from_secs(5)),
)
.await
.unwrap();
Expand Down