Skip to content

Commit

Permalink
Fix runtime start calling (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets authored Apr 26, 2024
1 parent 3263306 commit e8916bf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
5 changes: 4 additions & 1 deletion plugins/zenoh-plugin-storage-manager/tests/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ async fn test_updates_in_order() {
)
.unwrap();

let runtime = zenoh::runtime::Runtime::new(config).await.unwrap();
let runtime = zenoh::runtime::RuntimeBuilder::new(config)
.build()
.await
.unwrap();
let storage =
zenoh_plugin_storage_manager::StoragesPlugin::start("storage-manager", &runtime).unwrap();

Expand Down
5 changes: 4 additions & 1 deletion plugins/zenoh-plugin-storage-manager/tests/wildcard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ async fn test_wild_card_in_order() {
)
.unwrap();

let runtime = zenoh::runtime::Runtime::new(config).await.unwrap();
let runtime = zenoh::runtime::RuntimeBuilder::new(config)
.build()
.await
.unwrap();
let storage =
zenoh_plugin_storage_manager::StoragesPlugin::start("storage-manager", &runtime).unwrap();

Expand Down
23 changes: 5 additions & 18 deletions zenoh/src/net/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ impl RuntimeBuilder {
*handler.runtime.write().unwrap() = Runtime::downgrade(&runtime);
get_mut_unchecked(&mut runtime.state.router.clone()).init_link_state(runtime.clone());

// Admin space
if start_admin_space {
AdminSpace::start(&runtime, LONG_VERSION.clone()).await;
}

// Start plugins
#[cfg(all(feature = "unstable", feature = "plugins"))]
crate::plugins::loader::start_plugins(&runtime);
Expand Down Expand Up @@ -184,11 +189,6 @@ impl RuntimeBuilder {
}
});

// Admin space
if start_admin_space {
AdminSpace::start(&runtime, LONG_VERSION.clone()).await;
}

Ok(runtime)
}
}
Expand All @@ -210,19 +210,6 @@ impl StructVersion for Runtime {
impl PluginStartArgs for Runtime {}

impl Runtime {
pub async fn new(config: Config) -> ZResult<Runtime> {
// Create plugin_manager and load plugins
let mut runtime = Runtime::init(config).await?;
match runtime.start().await {
Ok(()) => Ok(runtime),
Err(err) => Err(err),
}
}

pub(crate) async fn init(config: Config) -> ZResult<Runtime> {
RuntimeBuilder::new(config).build().await
}

#[inline(always)]
pub(crate) fn manager(&self) -> &TransportManager {
&self.state.manager
Expand Down
2 changes: 1 addition & 1 deletion zenoh/src/net/runtime/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub enum Loop {
}

impl Runtime {
pub(crate) async fn start(&mut self) -> ZResult<()> {
pub async fn start(&mut self) -> ZResult<()> {
match self.whatami() {
WhatAmI::Client => self.start_client().await,
WhatAmI::Peer => self.start_peer().await,
Expand Down
3 changes: 2 additions & 1 deletion zenoh/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::prelude::{KeyExpr, Parameters};
use crate::publication::*;
use crate::query::*;
use crate::queryable::*;
use crate::runtime::RuntimeBuilder;
#[cfg(feature = "unstable")]
use crate::sample::Attachment;
use crate::sample::DataInfo;
Expand Down Expand Up @@ -824,7 +825,7 @@ impl Session {
tracing::debug!("Config: {:?}", &config);
let aggregated_subscribers = config.aggregation().subscribers().clone();
let aggregated_publishers = config.aggregation().publishers().clone();
let mut runtime = Runtime::init(config).await?;
let mut runtime = RuntimeBuilder::new(config).build().await?;

let mut session = Self::init(
runtime.clone(),
Expand Down
8 changes: 5 additions & 3 deletions zenoh/tests/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::time::Duration;
use zenoh::prelude::r#async::*;
use zenoh::runtime::Runtime;
use zenoh::runtime::{Runtime, RuntimeBuilder};
use zenoh_core::ztimeout;

const TIMEOUT: Duration = Duration::from_secs(60);
Expand Down Expand Up @@ -209,7 +209,8 @@ async fn open_session_unicast_runtime(endpoints: &[&str]) -> (Runtime, Runtime)
.collect::<Vec<_>>();
config.scouting.multicast.set_enabled(Some(false)).unwrap();
println!("[ ][01a] Creating r1 session runtime: {:?}", endpoints);
let r1 = Runtime::new(config).await.unwrap();
let mut r1 = RuntimeBuilder::new(config).build().await.unwrap();
r1.start().await.unwrap();

let mut config = config::peer();
config.connect.endpoints = endpoints
Expand All @@ -218,7 +219,8 @@ async fn open_session_unicast_runtime(endpoints: &[&str]) -> (Runtime, Runtime)
.collect::<Vec<_>>();
config.scouting.multicast.set_enabled(Some(false)).unwrap();
println!("[ ][02a] Creating r2 session runtime: {:?}", endpoints);
let r2 = Runtime::new(config).await.unwrap();
let mut r2 = RuntimeBuilder::new(config).build().await.unwrap();
r2.start().await.unwrap();

(r1, r2)
}
Expand Down

0 comments on commit e8916bf

Please sign in to comment.