Skip to content

Commit

Permalink
Refactor endpoint (#178)
Browse files Browse the repository at this point in the history
* refactor endpoint and more

* update health

* update logging

* clippy
  • Loading branch information
xlc authored May 14, 2024
1 parent d354fea commit 7fa3132
Show file tree
Hide file tree
Showing 9 changed files with 544 additions and 270 deletions.
51 changes: 45 additions & 6 deletions src/extensions/api/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use jsonrpsee::server::ServerHandle;
use serde_json::json;
use std::{net::SocketAddr, sync::Arc};
use std::{net::SocketAddr, sync::Arc, time::Duration};
use tokio::sync::mpsc;

use super::eth::EthApi;
Expand Down Expand Up @@ -61,7 +61,14 @@ async fn create_client() -> (
) {
let (addr, server, head_rx, finalized_head_rx, block_hash_rx) = create_server().await;

let client = Client::with_endpoints([format!("ws://{addr}")]).unwrap();
let client = Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();

(client, server, head_rx, finalized_head_rx, block_hash_rx)
}
Expand Down Expand Up @@ -168,7 +175,14 @@ async fn rotate_endpoint_on_stale() {
let (addr, server, mut head_rx, _, mut block_rx) = create_server().await;
let (addr2, server2, mut head_rx2, _, mut block_rx2) = create_server().await;

let client = Client::with_endpoints([format!("ws://{addr}"), format!("ws://{addr2}")]).unwrap();
let client = Client::new(
[format!("ws://{addr}"), format!("ws://{addr2}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();
let api = SubstrateApi::new(Arc::new(client), std::time::Duration::from_millis(100));

let head = api.get_head();
Expand Down Expand Up @@ -231,7 +245,14 @@ async fn rotate_endpoint_on_head_mismatch() {
let (addr1, server1, mut head_rx1, mut finalized_head_rx1, mut block_rx1) = create_server().await;
let (addr2, server2, mut head_rx2, mut finalized_head_rx2, mut block_rx2) = create_server().await;

let client = Client::with_endpoints([format!("ws://{addr1}"), format!("ws://{addr2}")]).unwrap();
let client = Client::new(
[format!("ws://{addr1}"), format!("ws://{addr2}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();

let client = Arc::new(client);
let api = SubstrateApi::new(client.clone(), std::time::Duration::from_millis(100));
Expand Down Expand Up @@ -332,7 +353,16 @@ async fn rotate_endpoint_on_head_mismatch() {
#[tokio::test]
async fn substrate_background_tasks_abort_on_drop() {
let (addr, _server, mut head_rx, mut finalized_head_rx, _) = create_server().await;
let client = Arc::new(Client::with_endpoints([format!("ws://{addr}")]).unwrap());
let client = Arc::new(
Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap(),
);
let api = SubstrateApi::new(client, std::time::Duration::from_millis(100));

// background tasks started
Expand All @@ -352,7 +382,16 @@ async fn substrate_background_tasks_abort_on_drop() {
#[tokio::test]
async fn eth_background_tasks_abort_on_drop() {
let (addr, _server, mut subscription_rx, mut block_rx) = create_eth_server().await;
let client = Arc::new(Client::with_endpoints([format!("ws://{addr}")]).unwrap());
let client = Arc::new(
Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap(),
);

let api = EthApi::new(client, std::time::Duration::from_millis(100));

Expand Down
Loading

0 comments on commit 7fa3132

Please sign in to comment.