From d02a57fe2e9cfa83ac5064f11a92399d0be730b4 Mon Sep 17 00:00:00 2001 From: Nick Pavlov Date: Wed, 12 Jul 2023 17:54:14 +0300 Subject: [PATCH 1/9] feat(http): added versions endpoint --- crates/created-swarm/src/swarm.rs | 3 ++- crates/system-services/src/deployer.rs | 16 ++++++++++++++++ crates/system-services/src/lib.rs | 1 + nox/src/http.rs | 23 ++++++++++++++++++++++- nox/src/lib.rs | 21 +++++++++++++++++++++ nox/src/main.rs | 3 ++- nox/src/node.rs | 18 +++++++++++++++--- 7 files changed, 79 insertions(+), 6 deletions(-) diff --git a/crates/created-swarm/src/swarm.rs b/crates/created-swarm/src/swarm.rs index 4f7660efc2..8b739bb80b 100644 --- a/crates/created-swarm/src/swarm.rs +++ b/crates/created-swarm/src/swarm.rs @@ -350,7 +350,8 @@ pub fn create_swarm_with_runtime( listen_on: config.listen_on.clone(), manager: management_peer_id, }); - let mut node = Node::new(resolved, vm_config, "some version").expect("create node"); + let mut node = + Node::new(resolved, vm_config, "some version", "some version").expect("create node"); node.listen(vec![config.listen_on.clone()]).expect("listen"); ( diff --git a/crates/system-services/src/deployer.rs b/crates/system-services/src/deployer.rs index 85eb0f03e5..9c5e947c4d 100644 --- a/crates/system-services/src/deployer.rs +++ b/crates/system-services/src/deployer.rs @@ -65,6 +65,14 @@ pub struct Deployer { config: SystemServicesConfig, } +#[derive(Debug, Clone)] +pub struct Versions { + pub aqua_ipfs_version: &'static str, + pub trust_graph_version: &'static str, + pub registry_version: &'static str, + pub decider_version: &'static str, +} + impl Deployer { pub fn new( services: ParticleAppServices, @@ -85,6 +93,14 @@ impl Deployer { config, } } + pub fn versions(&self) -> Versions { + Versions { + aqua_ipfs_version: aqua_ipfs_distro::VERSION, + trust_graph_version: trust_graph_distro::VERSION, + registry_version: registry_distro::VERSION, + decider_version: decider_distro::VERSION, + } + } async fn deploy_system_service(&self, key: &ServiceKey) -> eyre::Result<()> { match key { diff --git a/crates/system-services/src/lib.rs b/crates/system-services/src/lib.rs index b95f75d0b5..39d7635026 100644 --- a/crates/system-services/src/lib.rs +++ b/crates/system-services/src/lib.rs @@ -3,3 +3,4 @@ mod deployer; pub use deployer::Deployer; +pub use deployer::Versions; diff --git a/nox/src/http.rs b/nox/src/http.rs index a3353a400f..2fad87aaf9 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -1,3 +1,4 @@ +use crate::Versions; use axum::body::Body; use axum::http::header::CONTENT_TYPE; use axum::{ @@ -45,6 +46,19 @@ async fn handle_peer_id(State(state): State) -> Response { .into_response() } +async fn handle_versions(State(state): State) -> Response { + let versions = &state.0.versions; + Json(json!({ + "node": versions.node_version, + "air": versions.air_version, + "aqua_ipfs": versions.system_service.aqua_ipfs_version, + "trust_graph": versions.system_service.trust_graph_version, + "registry": versions.system_service.registry_version, + "decider": versions.system_service.decider_version, + })) + .into_response() +} + #[derive(Debug, Clone)] struct RouteState(Arc); @@ -52,17 +66,24 @@ struct RouteState(Arc); struct Inner { registry: Option, peer_id: PeerId, + versions: Versions, } pub async fn start_http_endpoint( listen_addr: SocketAddr, registry: Option, peer_id: PeerId, + versions: Versions, ) { - let state = RouteState(Arc::new(Inner { registry, peer_id })); + let state = RouteState(Arc::new(Inner { + registry, + peer_id, + versions, + })); let app: Router = Router::new() .route("/metrics", get(handle_metrics)) .route("/peer_id", get(handle_peer_id)) + .route("/versions", get(handle_versions)) .fallback(handler_404) .with_state(state); diff --git a/nox/src/lib.rs b/nox/src/lib.rs index a8f9408bc8..7e563bcb4c 100644 --- a/nox/src/lib.rs +++ b/nox/src/lib.rs @@ -55,3 +55,24 @@ pub use kademlia::Command as KademliaCommand; pub use layers::log_layer; pub use layers::tokio_console_layer; pub use layers::tracing_layer; + +#[derive(Debug, Clone)] +pub struct Versions { + pub node_version: &'static str, + pub air_version: &'static str, + pub system_service: system_services::Versions, +} + +impl Versions { + pub fn new( + node_version: &'static str, + air_version: &'static str, + system_service: system_services::Versions, + ) -> Self { + Self { + node_version, + air_version, + system_service, + } + } +} diff --git a/nox/src/main.rs b/nox/src/main.rs index c0a002df93..57939d1178 100644 --- a/nox/src/main.rs +++ b/nox/src/main.rs @@ -136,7 +136,8 @@ async fn start_fluence(config: ResolvedConfig) -> eyre::Result { let vm_config = vm_config(&config); let mut node: Box>> = - Node::new(config, vm_config, VERSION).wrap_err("error create node instance")?; + Node::new(config, vm_config, VERSION, air_interpreter_wasm::VERSION) + .wrap_err("error create node instance")?; node.listen(listen_addrs).wrap_err("error on listen")?; let node_exit_outlet = node.start(peer_id).await.wrap_err("node failed to start")?; diff --git a/nox/src/node.rs b/nox/src/node.rs index fcdedb5f4e..223d4ff95c 100644 --- a/nox/src/node.rs +++ b/nox/src/node.rs @@ -56,7 +56,7 @@ use tokio::task; use crate::builtins::make_peer_builtin; use crate::dispatcher::Dispatcher; use crate::effectors::Effectors; -use crate::Connectivity; +use crate::{Connectivity, Versions}; use super::behaviour::FluenceNetworkBehaviour; use crate::behaviour::FluenceNetworkBehaviourEvent; @@ -91,6 +91,7 @@ pub struct Node { pub key_manager: KeyManager, allow_local_addresses: bool, + versions: Versions, } impl Node { @@ -98,6 +99,7 @@ impl Node { config: ResolvedConfig, vm_config: RT::Config, node_version: &'static str, + air_version: &'static str, ) -> eyre::Result> { let key_pair: Keypair = config.node_config.root_key_pair.clone().into(); let transport = config.transport_config.transport; @@ -304,6 +306,12 @@ impl Node { system_services_config, ); + let versions = Versions::new( + node_version, + air_version, + system_services_deployer.versions(), + ); + Ok(Self::with( particle_stream, effects_in, @@ -325,6 +333,7 @@ impl Node { builtins_peer_id, key_manager, allow_local_addresses, + versions, )) } @@ -391,6 +400,7 @@ impl Node { builtins_management_peer_id: PeerId, key_manager: KeyManager, allow_local_addresses: bool, + versions: Versions, ) -> Box { let node_service = Self { particle_stream, @@ -415,6 +425,7 @@ impl Node { builtins_management_peer_id, key_manager, allow_local_addresses, + versions, }; Box::new(node_service) @@ -441,11 +452,12 @@ impl Node { let task_name = format!("node-{peer_id}"); let libp2p_metrics = self.libp2p_metrics; let allow_local_addresses = self.allow_local_addresses; + let versions = self.versions; task::Builder::new().name(&task_name.clone()).spawn(async move { let mut http_server = if let Some(http_listen_addr) = http_listen_addr{ log::info!("Starting http endpoint at {}", http_listen_addr); - start_http_endpoint(http_listen_addr, registry, peer_id).boxed() + start_http_endpoint(http_listen_addr, registry, peer_id, versions).boxed() } else { futures::future::pending().boxed() }; @@ -559,7 +571,7 @@ mod tests { None, ); let mut node: Box>> = - Node::new(config, vm_config, "some version").expect("create node"); + Node::new(config, vm_config, "some version", "some version").expect("create node"); let listening_address: Multiaddr = "/ip4/127.0.0.1/tcp/7777".parse().unwrap(); node.listen(vec![listening_address.clone()]).unwrap(); From 8836f53f9487bcf6336469e752f00009a8dbfe59 Mon Sep 17 00:00:00 2001 From: Nick Pavlov Date: Thu, 13 Jul 2023 15:05:31 +0300 Subject: [PATCH 2/9] add spell version --- nox/src/http.rs | 1 + nox/src/lib.rs | 11 +++++++---- nox/src/node.rs | 7 ++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/nox/src/http.rs b/nox/src/http.rs index 2fad87aaf9..e85f1553b3 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -51,6 +51,7 @@ async fn handle_versions(State(state): State) -> Response { Json(json!({ "node": versions.node_version, "air": versions.air_version, + "spell": versions.spell_version, "aqua_ipfs": versions.system_service.aqua_ipfs_version, "trust_graph": versions.system_service.trust_graph_version, "registry": versions.system_service.registry_version, diff --git a/nox/src/lib.rs b/nox/src/lib.rs index 7e563bcb4c..e09a61b285 100644 --- a/nox/src/lib.rs +++ b/nox/src/lib.rs @@ -58,20 +58,23 @@ pub use layers::tracing_layer; #[derive(Debug, Clone)] pub struct Versions { - pub node_version: &'static str, - pub air_version: &'static str, + pub node_version: String, + pub air_version: String, + pub spell_version: String, pub system_service: system_services::Versions, } impl Versions { pub fn new( - node_version: &'static str, - air_version: &'static str, + node_version: String, + air_version: String, + spell_version: String, system_service: system_services::Versions, ) -> Self { Self { node_version, air_version, + spell_version, system_service, } } diff --git a/nox/src/node.rs b/nox/src/node.rs index 223d4ff95c..e199c13888 100644 --- a/nox/src/node.rs +++ b/nox/src/node.rs @@ -262,7 +262,7 @@ impl Node { external_addresses: config.external_addresses(), node_version: env!("CARGO_PKG_VERSION"), air_version: air_interpreter_wasm::VERSION, - spell_version, + spell_version: spell_version.clone(), allowed_binaries, }; if let Some(m) = metrics_registry.as_mut() { @@ -307,8 +307,9 @@ impl Node { ); let versions = Versions::new( - node_version, - air_version, + node_version.to_string(), + air_version.to_string(), + spell_version, system_services_deployer.versions(), ); From 8d41f66ef4b7fadbf78dbf11ef982659e4cefd54 Mon Sep 17 00:00:00 2001 From: Nick Pavlov Date: Thu, 13 Jul 2023 23:15:45 +0300 Subject: [PATCH 3/9] Review fix --- nox/src/http.rs | 2 +- nox/src/lib.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nox/src/http.rs b/nox/src/http.rs index e85f1553b3..5c7f0c34e3 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -50,7 +50,7 @@ async fn handle_versions(State(state): State) -> Response { let versions = &state.0.versions; Json(json!({ "node": versions.node_version, - "air": versions.air_version, + "avm": versions.avm_version, "spell": versions.spell_version, "aqua_ipfs": versions.system_service.aqua_ipfs_version, "trust_graph": versions.system_service.trust_graph_version, diff --git a/nox/src/lib.rs b/nox/src/lib.rs index e09a61b285..909fbcaa79 100644 --- a/nox/src/lib.rs +++ b/nox/src/lib.rs @@ -59,7 +59,7 @@ pub use layers::tracing_layer; #[derive(Debug, Clone)] pub struct Versions { pub node_version: String, - pub air_version: String, + pub avm_version: String, pub spell_version: String, pub system_service: system_services::Versions, } @@ -67,13 +67,13 @@ pub struct Versions { impl Versions { pub fn new( node_version: String, - air_version: String, + avm_version: String, spell_version: String, system_service: system_services::Versions, ) -> Self { Self { node_version, - air_version, + avm_version, spell_version, system_service, } From dba2e345efa8d89c538361294b7ce1ecd961920f Mon Sep 17 00:00:00 2001 From: Nick Pavlov Date: Fri, 14 Jul 2023 14:58:15 +0300 Subject: [PATCH 4/9] Add tests --- Cargo.lock | 1 + Cargo.toml | 1 + nox/Cargo.toml | 3 +- nox/src/http.rs | 94 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e2f4b483d7..1eb5a61c5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4062,6 +4062,7 @@ dependencies = [ "fstrings", "futures", "humantime-serde", + "hyper", "itertools 0.11.0", "kademlia", "key-manager", diff --git a/Cargo.toml b/Cargo.toml index f3f29844eb..8b4ea7e9e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -137,6 +137,7 @@ itertools = "0.11.0" humantime-serde = "1.1.1" cid = "0.10.1" libipld = "0.16.0" +axum = "0.6.18" # Enable a small amount of optimization in debug mode [profile.dev] diff --git a/nox/Cargo.toml b/nox/Cargo.toml index b99fb8f136..c8ec32fb60 100644 --- a/nox/Cargo.toml +++ b/nox/Cargo.toml @@ -52,7 +52,7 @@ humantime-serde = { workspace = true } log = { workspace = true } tracing-log = { version = "0.1.3" } console-subscriber = { version = "0.1.10", features = ["parking_lot"] } -axum = { version = "0.6.18", features = ["macros"] } +axum = { workspace = true, features = ["macros"] } itertools = { workspace = true } eyre = { workspace = true } base64 = { workspace = true } @@ -75,6 +75,7 @@ rand = "0.8.5" bs58 = { workspace = true } connected-client = { path = "../crates/connected-client" } log-utils = { workspace = true } +hyper = "0.14.10" [[bench]] name = "network_api_bench" diff --git a/nox/src/http.rs b/nox/src/http.rs index 5c7f0c34e3..9277cf8ecf 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -93,3 +93,97 @@ pub async fn start_http_endpoint( .await .expect("Could not make http endpoint") } + +#[cfg(test)] +mod tests { + use super::*; + use axum::http::Request; + use std::net::{SocketAddr, TcpListener}; + use tokio::time::sleep; + + fn get_free_tcp_port() -> u16 { + let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind to port 0"); + let socket_addr = listener + .local_addr() + .expect("Failed to retrieve local address"); + let port = socket_addr.port(); + drop(listener); + port + } + + fn test_versions() -> Versions { + Versions { + node_version: "node_test_version".to_string(), + avm_version: "avm_test_version".to_string(), + spell_version: "spell_test_version".to_string(), + system_service: system_services::Versions { + aqua_ipfs_version: "aqua_ipfs_test_version", + trust_graph_version: "trust_graph_test_version", + registry_version: "registry_test_version", + decider_version: "decider_test_version", + }, + } + } + + #[tokio::test] + async fn test_version_route() { + // Create a test server + let port = get_free_tcp_port(); + let addr = format!("127.0.0.1:{port}").parse::().unwrap(); + + tokio::spawn(async move { + start_http_endpoint(addr, None, PeerId::random(), test_versions()).await; + }); + + sleep(tokio::time::Duration::from_secs(1)).await; + + let client = hyper::Client::new(); + + let response = client + .request( + Request::builder() + .uri(format!("http://{}/versions", addr)) + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap(); + let status = response.status(); + let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + assert_eq!(status, StatusCode::OK); + assert_eq!(&body[..], b"{\"node\":\"node_test_version\",\"avm\":\"avm_test_version\",\"spell\":\"spell_test_version\",\"aqua_ipfs\":\"aqua_ipfs_test_version\",\"trust_graph\":\"trust_graph_test_version\",\"registry\":\"registry_test_version\",\"decider\":\"decider_test_version\"}"); + } + + #[tokio::test] + async fn test_peer_id_route() { + // Create a test server + let port = get_free_tcp_port(); + let addr = format!("127.0.0.1:{port}").parse::().unwrap(); + let peer_id = PeerId::random(); + + tokio::spawn(async move { + start_http_endpoint(addr, None, peer_id, test_versions()).await; + }); + + sleep(tokio::time::Duration::from_secs(1)).await; + + let client = hyper::Client::new(); + + let response = client + .request( + Request::builder() + .uri(format!("http://{}/peer_id", addr)) + .body(Body::empty()) + .unwrap(), + ) + .await + .unwrap(); + let status = response.status(); + let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + assert_eq!(status, StatusCode::OK); + assert_eq!( + &body[..], + format!("{{\"peer_id\":\"{}\"}}", peer_id).as_bytes() + ); + } +} From 77aa163bab5668176aeaa3e6348308e8d45e5c74 Mon Sep 17 00:00:00 2001 From: Nick Pavlov Date: Fri, 14 Jul 2023 18:55:44 +0300 Subject: [PATCH 5/9] Review fixes --- nox/src/http.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nox/src/http.rs b/nox/src/http.rs index 9277cf8ecf..caa9f50618 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -151,7 +151,7 @@ mod tests { let status = response.status(); let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); assert_eq!(status, StatusCode::OK); - assert_eq!(&body[..], b"{\"node\":\"node_test_version\",\"avm\":\"avm_test_version\",\"spell\":\"spell_test_version\",\"aqua_ipfs\":\"aqua_ipfs_test_version\",\"trust_graph\":\"trust_graph_test_version\",\"registry\":\"registry_test_version\",\"decider\":\"decider_test_version\"}"); + assert_eq!(&body[..], r#"{"node":"node_test_version","avm":"avm_test_version","spell":"spell_test_version","aqua_ipfs":"aqua_ipfs_test_version","trust_graph":"trust_graph_test_version","registry":"registry_test_version","decider":"decider_test_version"}"#.as_bytes()); } #[tokio::test] @@ -183,7 +183,7 @@ mod tests { assert_eq!(status, StatusCode::OK); assert_eq!( &body[..], - format!("{{\"peer_id\":\"{}\"}}", peer_id).as_bytes() + format!(r#"{{"peer_id":"{}"}}"#, peer_id).as_bytes() ); } } From efae8f5e5f8fa4b095a06274b4c76c5c6dc4de2d Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Mon, 17 Jul 2023 13:08:17 -0500 Subject: [PATCH 6/9] Update nox/src/http.rs --- nox/src/http.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nox/src/http.rs b/nox/src/http.rs index caa9f50618..9951e44e2c 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -151,7 +151,7 @@ mod tests { let status = response.status(); let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); assert_eq!(status, StatusCode::OK); - assert_eq!(&body[..], r#"{"node":"node_test_version","avm":"avm_test_version","spell":"spell_test_version","aqua_ipfs":"aqua_ipfs_test_version","trust_graph":"trust_graph_test_version","registry":"registry_test_version","decider":"decider_test_version"}"#.as_bytes()); + assert_eq!(&body[..], br#"{"node":"node_test_version","avm":"avm_test_version","spell":"spell_test_version","aqua_ipfs":"aqua_ipfs_test_version","trust_graph":"trust_graph_test_version","registry":"registry_test_version","decider":"decider_test_version"}"#); } #[tokio::test] From db7df8d7fbd6b2e491edb6779a547a32f22a38aa Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Mon, 17 Jul 2023 13:08:27 -0500 Subject: [PATCH 7/9] Update nox/src/http.rs --- nox/src/http.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nox/src/http.rs b/nox/src/http.rs index 9951e44e2c..04ce537cf4 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -183,7 +183,7 @@ mod tests { assert_eq!(status, StatusCode::OK); assert_eq!( &body[..], - format!(r#"{{"peer_id":"{}"}}"#, peer_id).as_bytes() + format!(br#"{{"peer_id":"{}"}}"#, peer_id) ); } } From db228b764c6b5f74c710337c7a9734e1f2a50743 Mon Sep 17 00:00:00 2001 From: folex <0xdxdy@gmail.com> Date: Mon, 17 Jul 2023 19:53:06 -0500 Subject: [PATCH 8/9] chore: oops, fix typo --- nox/src/http.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nox/src/http.rs b/nox/src/http.rs index 04ce537cf4..9951e44e2c 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -183,7 +183,7 @@ mod tests { assert_eq!(status, StatusCode::OK); assert_eq!( &body[..], - format!(br#"{{"peer_id":"{}"}}"#, peer_id) + format!(r#"{{"peer_id":"{}"}}"#, peer_id).as_bytes() ); } } From e5987fc171c5fc9c1904c8b24c7e15dedc5a94d7 Mon Sep 17 00:00:00 2001 From: Nick Pavlov Date: Tue, 18 Jul 2023 17:46:32 +0300 Subject: [PATCH 9/9] chore: fix test timeout --- nox/src/http.rs | 22 +++++++++++++--------- nox/src/node.rs | 4 ++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/nox/src/http.rs b/nox/src/http.rs index 9951e44e2c..1ac541d814 100644 --- a/nox/src/http.rs +++ b/nox/src/http.rs @@ -14,6 +14,7 @@ use prometheus_client::registry::Registry; use serde_json::json; use std::net::SocketAddr; use std::sync::Arc; +use tokio::sync::Notify; async fn handler_404() -> impl IntoResponse { (StatusCode::NOT_FOUND, "nothing to see here") @@ -75,6 +76,7 @@ pub async fn start_http_endpoint( registry: Option, peer_id: PeerId, versions: Versions, + notify: Arc, ) { let state = RouteState(Arc::new(Inner { registry, @@ -88,10 +90,9 @@ pub async fn start_http_endpoint( .fallback(handler_404) .with_state(state); - axum::Server::bind(&listen_addr) - .serve(app.into_make_service()) - .await - .expect("Could not make http endpoint") + let server = axum::Server::bind(&listen_addr).serve(app.into_make_service()); + notify.notify_one(); + server.await.expect("Could not make http endpoint") } #[cfg(test)] @@ -99,7 +100,6 @@ mod tests { use super::*; use axum::http::Request; use std::net::{SocketAddr, TcpListener}; - use tokio::time::sleep; fn get_free_tcp_port() -> u16 { let listener = TcpListener::bind("127.0.0.1:0").expect("Failed to bind to port 0"); @@ -131,11 +131,13 @@ mod tests { let port = get_free_tcp_port(); let addr = format!("127.0.0.1:{port}").parse::().unwrap(); + let notify = Arc::new(Notify::new()); + let cloned_notify = notify.clone(); tokio::spawn(async move { - start_http_endpoint(addr, None, PeerId::random(), test_versions()).await; + start_http_endpoint(addr, None, PeerId::random(), test_versions(), cloned_notify).await; }); - sleep(tokio::time::Duration::from_secs(1)).await; + notify.notified().await; let client = hyper::Client::new(); @@ -161,11 +163,13 @@ mod tests { let addr = format!("127.0.0.1:{port}").parse::().unwrap(); let peer_id = PeerId::random(); + let notify = Arc::new(Notify::new()); + let cloned_notify = notify.clone(); tokio::spawn(async move { - start_http_endpoint(addr, None, peer_id, test_versions()).await; + start_http_endpoint(addr, None, peer_id, test_versions(), cloned_notify).await; }); - sleep(tokio::time::Duration::from_secs(1)).await; + notify.notified().await; let client = hyper::Client::new(); diff --git a/nox/src/node.rs b/nox/src/node.rs index e199c13888..d9dfe1730e 100644 --- a/nox/src/node.rs +++ b/nox/src/node.rs @@ -50,7 +50,7 @@ use sorcerer::Sorcerer; use spell_event_bus::api::{PeerEvent, SpellEventBusApi, TriggerEvent}; use spell_event_bus::bus::SpellEventBus; use system_services::Deployer; -use tokio::sync::{mpsc, oneshot}; +use tokio::sync::{mpsc, oneshot, Notify}; use tokio::task; use crate::builtins::make_peer_builtin; @@ -458,7 +458,7 @@ impl Node { task::Builder::new().name(&task_name.clone()).spawn(async move { let mut http_server = if let Some(http_listen_addr) = http_listen_addr{ log::info!("Starting http endpoint at {}", http_listen_addr); - start_http_endpoint(http_listen_addr, registry, peer_id, versions).boxed() + start_http_endpoint(http_listen_addr, registry, peer_id, versions, Arc::new(Notify::new())).boxed() } else { futures::future::pending().boxed() };