Add a an optional timeout to thin_client
Such that a negative test like test_transaction_count doesn't have to wait num_retries * default_timeout.
This commit is contained in:
parent
3cc0dd0d1e
commit
ecc87ab1aa
|
@ -10,6 +10,7 @@ use cluster_info::{ClusterInfo, ClusterInfoError, NodeInfo};
|
||||||
use log::Level;
|
use log::Level;
|
||||||
use ncp::Ncp;
|
use ncp::Ncp;
|
||||||
use packet::PACKET_DATA_SIZE;
|
use packet::PACKET_DATA_SIZE;
|
||||||
|
use reqwest;
|
||||||
use result::{Error, Result};
|
use result::{Error, Result};
|
||||||
use rpc_request::{RpcClient, RpcRequest};
|
use rpc_request::{RpcClient, RpcRequest};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
|
@ -53,9 +54,36 @@ impl ThinClient {
|
||||||
rpc_addr: SocketAddr,
|
rpc_addr: SocketAddr,
|
||||||
transactions_addr: SocketAddr,
|
transactions_addr: SocketAddr,
|
||||||
transactions_socket: UdpSocket,
|
transactions_socket: UdpSocket,
|
||||||
|
) -> Self {
|
||||||
|
Self::new_from_client(
|
||||||
|
rpc_addr,
|
||||||
|
transactions_addr,
|
||||||
|
transactions_socket,
|
||||||
|
RpcClient::new(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_with_timeout(
|
||||||
|
rpc_addr: SocketAddr,
|
||||||
|
transactions_addr: SocketAddr,
|
||||||
|
transactions_socket: UdpSocket,
|
||||||
|
timeout: Duration,
|
||||||
|
) -> Self {
|
||||||
|
let rpc_client = reqwest::Client::builder()
|
||||||
|
.timeout(timeout)
|
||||||
|
.build()
|
||||||
|
.expect("build rpc client");
|
||||||
|
Self::new_from_client(rpc_addr, transactions_addr, transactions_socket, rpc_client)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_from_client(
|
||||||
|
rpc_addr: SocketAddr,
|
||||||
|
transactions_addr: SocketAddr,
|
||||||
|
transactions_socket: UdpSocket,
|
||||||
|
rpc_client: RpcClient,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
ThinClient {
|
ThinClient {
|
||||||
rpc_client: RpcClient::new(),
|
rpc_client,
|
||||||
rpc_addr,
|
rpc_addr,
|
||||||
transactions_addr,
|
transactions_addr,
|
||||||
transactions_socket,
|
transactions_socket,
|
||||||
|
@ -686,7 +714,8 @@ mod tests {
|
||||||
logger::setup();
|
logger::setup();
|
||||||
let addr = "0.0.0.0:1234".parse().unwrap();
|
let addr = "0.0.0.0:1234".parse().unwrap();
|
||||||
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||||
let mut client = ThinClient::new(addr, addr, transactions_socket);
|
let mut client =
|
||||||
|
ThinClient::new_with_timeout(addr, addr, transactions_socket, Duration::from_secs(2));
|
||||||
assert_eq!(client.transaction_count(), 0);
|
assert_eq!(client.transaction_count(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue