Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn rpc::Client::new into a sync fn by not performing the health check on creation #169

Merged
merged 3 commits into from
Mar 10, 2020
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
8 changes: 7 additions & 1 deletion tendermint-lite/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ fn main() {
let trusting_period = Duration::new(6000, 0);

// setup requester for primary peer
let client = block_on(rpc::Client::new(&RPC_ADDR.parse().unwrap())).unwrap();
let client = rpc::Client::new(RPC_ADDR.parse().unwrap());

if let Err(err) = block_on(client.health()) {
eprintln!("error: health check failed: {}", err);
std::process::exit(1);
}

let req = RPCRequester::new(client);
let mut store = MemStore::new();

Expand Down
2 changes: 1 addition & 1 deletion tendermint-lite/src/requester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ mod tests {
#[test]
#[ignore]
fn test_val_set() {
let client = block_on(rpc::Client::new(&"localhost:26657".parse().unwrap())).unwrap();
let client = rpc::Client::new("localhost:26657".parse().unwrap());
let req = RPCRequester::new(client);
let r1 = req.validator_set(5).unwrap();
let r2 = req.signed_header(5).unwrap();
Expand Down
8 changes: 2 additions & 6 deletions tendermint/src/rpc/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ pub struct Client {

impl Client {
/// Create a new Tendermint RPC client, connecting to the given address
pub async fn new(address: &net::Address) -> Result<Self, Error> {
let client = Client {
address: address.clone(),
};
client.health().await?;
Ok(client)
pub fn new(address: net::Address) -> Self {
Self { address }
}

/// `/abci_info`: get information about the ABCI application.
Expand Down
10 changes: 9 additions & 1 deletion tendermint/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ mod rpc {

/// Get the address of the local node
pub fn localhost_rpc_client() -> Client {
block_on(Client::new(&"tcp://127.0.0.1:26657".parse().unwrap())).unwrap()
Client::new("tcp://127.0.0.1:26657".parse().unwrap())
}

/// `/health` endpoint
#[test]
#[ignore]
fn health() {
let result = block_on(localhost_rpc_client().health());
assert!(result.is_ok(), "health check failed");
}

/// `/abci_info` endpoint
Expand Down