mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 08:51:04 +00:00
Tweak test to reduce chance of failure, and need jsonrpsee/server for tests (#2057)
This commit is contained in:
@@ -93,6 +93,7 @@ wasm-bindgen-futures = { workspace = true, optional = true }
|
|||||||
tower = { workspace = true }
|
tower = { workspace = true }
|
||||||
hyper = { workspace = true }
|
hyper = { workspace = true }
|
||||||
http-body = { workspace = true }
|
http-body = { workspace = true }
|
||||||
|
jsonrpsee = { workspace = true, features = ["server"] }
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
default-features = true
|
default-features = true
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ async fn sub_with_reconnect() {
|
|||||||
let (handle, addr) = run_server().await.unwrap();
|
let (handle, addr) = run_server().await.unwrap();
|
||||||
let client = RpcClient::builder().build(addr.clone()).await.unwrap();
|
let client = RpcClient::builder().build(addr.clone()).await.unwrap();
|
||||||
|
|
||||||
let mut sub = client
|
let sub = client
|
||||||
.subscribe(
|
.subscribe(
|
||||||
"subscribe_lo".to_string(),
|
"subscribe_lo".to_string(),
|
||||||
None,
|
None,
|
||||||
@@ -54,24 +54,25 @@ async fn sub_with_reconnect() {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Tell server to shut down.
|
||||||
let _ = handle.send(());
|
let _ = handle.send(());
|
||||||
|
|
||||||
// Hack to wait for the server to restart.
|
// Drain any values from the subscription. We should end with a DisconnectedWillReconnect error,
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
// so that subscriptions have the opportunity to react to the fact that we were disconnected.
|
||||||
|
let sub_ended_with_disconnect_err = sub.fold(false, async |_, next| matches!(next, Err(DisconnectedWillReconnect(_))));
|
||||||
|
let sub_ended_with_disconnect_err = tokio::time::timeout(tokio::time::Duration::from_secs(5), sub_ended_with_disconnect_err)
|
||||||
|
.await
|
||||||
|
.expect("timeout should not be hit");
|
||||||
|
|
||||||
assert!(matches!(sub.next().await, Some(Ok(_))));
|
assert!(sub_ended_with_disconnect_err, "DisconnectedWillReconnect err was last message in sub");
|
||||||
assert!(matches!(
|
|
||||||
sub.next().await,
|
|
||||||
Some(Err(DisconnectedWillReconnect(_)))
|
|
||||||
));
|
|
||||||
|
|
||||||
// Restart the server.
|
// Start a new server at the same address as the old one. (This will wait a bit for the addr to be free)
|
||||||
let (_handle, _) = run_server_with_settings(Some(&addr), false).await.unwrap();
|
let (_handle, _) = run_server_with_settings(Some(&addr), false).await.unwrap();
|
||||||
|
|
||||||
// Hack to wait for the server to restart.
|
// Hack to wait for the server to restart.
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
|
||||||
// Subscription should work after reconnect.
|
// We can subscribe again on the same client and it should work.
|
||||||
let mut sub = client
|
let mut sub = client
|
||||||
.subscribe(
|
.subscribe(
|
||||||
"subscribe_lo".to_string(),
|
"subscribe_lo".to_string(),
|
||||||
@@ -137,7 +138,7 @@ async fn run_server_with_settings(
|
|||||||
}
|
}
|
||||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||||
|
|
||||||
if i >= 10 {
|
if i >= 100 {
|
||||||
panic!("Addr already in use");
|
panic!("Addr already in use");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user