Skip to content

Commit

Permalink
added retry logic test
Browse files Browse the repository at this point in the history
Signed-off-by: Iulian Barbu <[email protected]>
  • Loading branch information
iulianbarbu committed Aug 30, 2024
1 parent 9024ac1 commit 7e82332
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cumulus/client/relay-chain-rpc-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
[lints]
workspace = true

[dev-dependencies]
portpicker = "0.1.1"

[dependencies]
polkadot-overseer = { workspace = true, default-features = true }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,10 @@ impl ReconnectingWebsocketWorker {

#[cfg(test)]
mod test {
use super::url_to_string_with_port;
use std::time::Duration;

use super::{url_to_string_with_port, ClientManager};
use jsonrpsee::Methods;
use url::Url;

#[test]
Expand Down Expand Up @@ -493,4 +496,48 @@ mod test {
url_to_string_with_port(url)
);
}

#[tokio::test]
// Testing the retry logic at full means increasing CI with half a minute according
// to the current logic, so lets test it best effort.
async fn client_manager_retry_logic() {
let port = portpicker::pick_unused_port().unwrap();
let server = jsonrpsee::server::Server::builder()
.build(format!("127.0.0.1:{}", port))
.await
.unwrap();

// Wait three seconds while attempting connection.
let conn_res = tokio::spawn(async move {
tokio::time::timeout(
Duration::from_secs(3),
ClientManager::new(vec![format!("ws://127.0.0.1:{}", port)]),
)
.await
});

// Start the server too.
let server = tokio::spawn(async {
tokio::time::sleep(Duration::from_secs(10)).await;
server.start(Methods::default())
});

// By this time the client can not make a connection because the server is not up.
assert!(conn_res.await.unwrap().is_err());

// Trying to connect again to the RPC with a client that stays around for sufficient
// time to catche the RPC server online and connect to it.
let conn_res = tokio::spawn(async move {
tokio::time::timeout(
Duration::from_secs(8),
ClientManager::new(vec![format!("ws://127.0.0.1:{}", port)]),
)
.await
});
let res = conn_res.await.unwrap();
assert!(res.is_ok());
assert!(res.unwrap().is_ok());

server.await.unwrap();
}
}

0 comments on commit 7e82332

Please sign in to comment.