summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge_core
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-05-13 09:41:55 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-05-13 09:42:20 +0200
commit97b6f9e0fff7b279d1c33f618d629a0052f1a16b (patch)
tree1fccf349007b3785ddc17563c406a7a02ef0782c /crates/core/tedge_core
parentd1b953a27576c370f756112f62783e9801a0b6b3 (diff)
tedge_core: Run formatter
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/core/tedge_core')
-rw-r--r--crates/core/tedge_core/benches/simple_throughput.rs15
-rw-r--r--crates/core/tedge_core/src/communication.rs9
-rw-r--r--crates/core/tedge_core/src/configuration.rs11
-rw-r--r--crates/core/tedge_core/src/errors.rs1
-rw-r--r--crates/core/tedge_core/src/lib.rs61
-rw-r--r--crates/core/tedge_core/src/reactor.rs55
-rw-r--r--crates/core/tedge_core/tests/check_concurrent_messages.rs15
-rw-r--r--crates/core/tedge_core/tests/plugin_does_not_shutdown.rs35
-rw-r--r--crates/core/tedge_core/tests/plugin_does_not_support_message.rs19
-rw-r--r--crates/core/tedge_core/tests/plugin_panic_lifecycle.rs19
-rw-r--r--crates/core/tedge_core/tests/plugin_panics_in_msg_handler.rs45
-rw-r--r--crates/core/tedge_core/tests/plugin_send_to_self_name.rs54
-rw-r--r--crates/core/tedge_core/tests/verify_configuration_fails.rs18
13 files changed, 208 insertions, 149 deletions
diff --git a/crates/core/tedge_core/benches/simple_throughput.rs b/crates/core/tedge_core/benches/simple_throughput.rs
index d4f1ca4d..697a10cd 100644
--- a/crates/core/tedge_core/benches/simple_throughput.rs
+++ b/crates/core/tedge_core/benches/simple_throughput.rs
@@ -16,8 +16,7 @@ use tokio::sync::{Mutex, Notify};
#[derive(Debug)]
struct Measurement(u64);
-impl Message for Measurement {
-}
+impl Message for Measurement {}
pub struct ProducerPluginBuilder(Mutex<Option<tokio::sync::mpsc::Receiver<u64>>>);
@@ -185,11 +184,19 @@ async fn start_application(
let _ = tracing_subscriber::fmt::try_init();
let config_file_path = {
- let dir = std::env::current_exe().unwrap().parent().unwrap().join("../../../");
+ let dir = std::env::current_exe()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("../../../");
let mut name = std::path::PathBuf::from(std::file!());
name.set_extension("toml");
let filepath = dir.join(name);
- assert!(filepath.exists(), "Config file does not exist: {}", filepath.display());
+ assert!(
+ filepath.exists(),
+ "Config file does not exist: {}",
+ filepath.display()
+ );
filepath
};
diff --git a/crates/core/tedge_core/src/communication.rs b/crates/core/tedge_core/src/communication.rs
index 63128508..bb7a166a 100644
--- a/crates/core/tedge_core/src/communication.rs
+++ b/crates/core/tedge_core/src/communication.rs
@@ -210,8 +210,7 @@ mod tests {
#[derive(Debug)]
pub struct SupportedMessage;
- impl tedge_api::Message for SupportedMessage {
- }
+ impl tedge_api::Message for SupportedMessage {}
impl tedge_api::plugin::PluginDeclaration for Plug {
type HandledMessages = (SupportedMessage,);
@@ -245,14 +244,12 @@ mod tests {
#[derive(Debug)]
struct UnsupportedMessage;
- impl tedge_api::Message for UnsupportedMessage {
- }
+ impl tedge_api::Message for UnsupportedMessage {}
#[derive(Debug)]
struct OtherUnsupportedMessage;
- impl tedge_api::Message for OtherUnsupportedMessage {
- }
+ impl tedge_api::Message for OtherUnsupportedMessage {}
tedge_api::make_receiver_bundle!(pub struct UnsupportedMessageReceiver(UnsupportedMessage));
tedge_api::make_receiver_bundle!(pub struct OtherUnsupportedMessageReceiver(OtherUnsupportedMessage));
diff --git a/crates/core/tedge_core/src/configuration.rs b/crates/core/tedge_core/src/configuration.rs
index 12006fc9..1403215a 100644
--- a/crates/core/tedge_core/src/configuration.rs
+++ b/crates/core/tedge_core/src/configuration.rs
@@ -130,7 +130,10 @@ mod tests {
let c: PluginInstanceConfiguration = toml::from_str(s).unwrap();
assert_eq!(c.kind, PluginKind("foo".to_string()));
- assert_eq!(c.configuration, InstanceConfiguration::ConfigFilePath(PathBuf::from("path/to/file.toml")));
+ assert_eq!(
+ c.configuration,
+ InstanceConfiguration::ConfigFilePath(PathBuf::from("path/to/file.toml"))
+ );
}
#[test]
@@ -142,7 +145,9 @@ mod tests {
let c: PluginInstanceConfiguration = toml::from_str(s).unwrap();
assert_eq!(c.kind, PluginKind("foo".to_string()));
- assert!(std::matches!(c.configuration, InstanceConfiguration::Config(_)));
+ assert!(std::matches!(
+ c.configuration,
+ InstanceConfiguration::Config(_)
+ ));
}
}
-
diff --git a/crates/core/tedge_core/src/errors.rs b/crates/core/tedge_core/src/errors.rs
index 918e9b42..b46d8635 100644
--- a/crates/core/tedge_core/src/errors.rs
+++ b/crates/core/tedge_core/src/errors.rs
@@ -58,4 +58,3 @@ pub enum TedgeApplicationError {
}
pub(crate) type Result<T> = std::result::Result<T, TedgeApplicationError>;
-
diff --git a/crates/core/tedge_core/src/lib.rs b/crates/core/tedge_core/src/lib.rs
index 5988870e..32af7a48 100644
--- a/crates/core/tedge_core/src/lib.rs
+++ b/crates/core/tedge_core/src/lib.rs
@@ -71,7 +71,9 @@ impl TedgeApplication {
&self.config
}
- pub(crate) fn plugin_builders(&self) -> &HashMap<String, (HandleTypes, Box<dyn PluginBuilder<PluginDirectory>>)> {
+ pub(crate) fn plugin_builders(
+ &self,
+ ) -> &HashMap<String, (HandleTypes, Box<dyn PluginBuilder<PluginDirectory>>)> {
&self.plugin_builders
}
@@ -98,26 +100,32 @@ impl TedgeApplication {
self.config()
.plugins()
.iter()
- .map(|(plugin_name, plugin_cfg): (&String, &PluginInstanceConfiguration)| async {
- if let Some((_, builder)) = self.plugin_builders().get(plugin_cfg.kind().as_ref()) {
- debug!("Verifying {}", plugin_cfg.kind().as_ref());
- let res = plugin_cfg
- .configuration()
- .verify_with_builder(builder, self.config_path())
- .await
- .into_diagnostic()
- .map_err(TedgeApplicationError::PluginConfigVerificationFailed)
- .map(|_| ());
- (plugin_name.to_string(), res)
- } else {
- (
- plugin_name.to_string(),
- Err(TedgeApplicationError::UnknownPluginKind(
- plugin_cfg.kind().as_ref().to_string(),
- ))
- )
+ .map(
+ |(plugin_name, plugin_cfg): (&String, &PluginInstanceConfiguration)| {
+ async {
+ if let Some((_, builder)) =
+ self.plugin_builders().get(plugin_cfg.kind().as_ref())
+ {
+ debug!("Verifying {}", plugin_cfg.kind().as_ref());
+ let res = plugin_cfg
+ .configuration()
+ .verify_with_builder(builder, self.config_path())
+ .await
+ .into_diagnostic()
+ .map_err(TedgeApplicationError::PluginConfigVerificationFailed)
+ .map(|_| ());
+ (plugin_name.to_string(), res)
+ } else {
+ (
+ plugin_name.to_string(),
+ Err(TedgeApplicationError::UnknownPluginKind(
+ plugin_cfg.kind().as_ref().to_string(),
+ )),
+ )
+ }
}
- }.instrument(debug_span!("verify configuration", plugin.name = %plugin_name))
+ .instrument(debug_span!("verify configuration", plugin.name = %plugin_name))
+ },
)
.collect::<futures::stream::FuturesUnordered<_>>()
.collect::<Vec<(String, Result<()>)>>()
@@ -141,7 +149,10 @@ impl TedgeApplicationBuilder {
/// running once the application starts up, but merely that the application _knows_ about this
/// plugin builder and is able to construct a plugin with this builder, if necessary (e.g. if
/// configured in a configuration file).
- pub fn with_plugin_builder<PB: PluginBuilder<PluginDirectory>>(mut self, builder: PB) -> Result<Self> {
+ pub fn with_plugin_builder<PB: PluginBuilder<PluginDirectory>>(
+ mut self,
+ builder: PB,
+ ) -> Result<Self> {
let handle_types = PB::kind_message_types();
let kind_name = PB::kind_name();
event!(
@@ -152,7 +163,9 @@ impl TedgeApplicationBuilder {
);
if self.plugin_builders.contains_key(kind_name) {
- return Err(TedgeApplicationError::PluginKindExists(kind_name.to_string()))
+ return Err(TedgeApplicationError::PluginKindExists(
+ kind_name.to_string(),
+ ));
}
self.plugin_builders
@@ -191,7 +204,9 @@ impl TedgeApplicationBuilder {
}
#[cfg(test)]
- pub fn plugin_builders(&self) -> &HashMap<String, (HandleTypes, Box<dyn PluginBuilder<PluginDirectory>>)> {
+ pub fn plugin_builders(
+ &self,
+ ) -> &HashMap<String, (HandleTypes, Box<dyn PluginBuilder<PluginDirectory>>)> {
&self.plugin_builders
}
}
diff --git a/crates/core/tedge_core/src/reactor.rs b/crates/core/tedge_core/src/reactor.rs
index 0bcfea38..c3a4f2ba 100644
--- a/crates/core/tedge_core/src/reactor.rs
+++ b/crates/core/tedge_core/src/reactor.rs
@@ -60,36 +60,35 @@ impl Reactor {
// This is then collected into a CorePluginDirectory, our "addressbook type" that can be
// used to retrieve addresses for message passing.
let (core_sender, core_receiver) = tokio::sync::mpsc::channel(channel_size);
- let mut directory = tracing::debug_span!("core.build_plugin_directory")
- .in_scope(|| {
- let directory_iter = self.0.config().plugins().iter().map(|(pname, pconfig)| {
- // fetch the types the plugin claims to handle from the plugin builder identified
- // by the "kind" in the configuration of the instance
- let handle_types = self
- .0
- .plugin_builders()
- .get(pconfig.kind().as_ref())
- .map(|(handle_types, _)| {
- handle_types
- .get_types()
- .into_iter()
- .cloned()
- .collect::<Vec<MessageType>>()
- })
- .ok_or_else(|| {
- TedgeApplicationError::UnknownPluginKind(
- pconfig.kind().as_ref().to_string(),
- )
- })?;
+ let mut directory = tracing::debug_span!("core.build_plugin_directory").in_scope(|| {
+ let directory_iter = self.0.config().plugins().iter().map(|(pname, pconfig)| {
+ // fetch the types the plugin claims to handle from the plugin builder identified
+ // by the "kind" in the configuration of the instance
+ let handle_types = self
+ .0
+ .plugin_builders()
+ .get(pconfig.kind().as_ref())
+ .map(|(handle_types, _)| {
+ handle_types
+ .get_types()
+ .into_iter()
+ .cloned()
+ .collect::<Vec<MessageType>>()
+ })
+ .ok_or_else(|| {
+ TedgeApplicationError::UnknownPluginKind(
+ pconfig.kind().as_ref().to_string(),
+ )
+ })?;
- Ok((
- pname.to_string(),
- PluginInfo::new(handle_types, channel_size),
- ))
- });
+ Ok((
+ pname.to_string(),
+ PluginInfo::new(handle_types, channel_size),
+ ))
+ });
- CorePluginDirectory::collect_from(directory_iter, core_sender)
- })?;
+ CorePluginDirectory::collect_from(directory_iter, core_sender)
+ })?;
// Start preparing the plugin instantiation...
let plugin_instantiation_prep = tracing::debug_span!("core.plugin_instantiation_prep")
diff --git a/crates/core/tedge_core/tests/check_concurrent_messages.rs b/crates/core/tedge_core/tests/check_concurrent_messages.rs
index 0dcfe963..8465992e 100644
--- a/crates/core/tedge_core/tests/check_concurrent_messages.rs
+++ b/crates/core/tedge_core/tests/check_concurrent_messages.rs
@@ -23,8 +23,7 @@ const MESSAGE_COUNT: usize = 1000;
#[derive(Debug)]
struct Spam;
-impl Message for Spam {
-}
+impl Message for Spam {}
pub struct SpammyPluginBuilder;
@@ -172,11 +171,19 @@ async fn test_verify_concurrent_messages() -> miette::Result<()> {
let _ = tracing_subscriber::fmt::try_init();
let config_file_path = {
- let dir = std::env::current_exe().unwrap().parent().unwrap().join("../../../");
+ let dir = std::env::current_exe()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("../../../");
let mut name = std::path::PathBuf::from(std::file!());
name.set_extension("toml");
let filepath = dir.join(name);
- assert!(filepath.exists(), "Config file does not exist: {}", filepath.display());
+ assert!(
+ filepath.exists(),
+ "Config file does not exist: {}",
+ filepath.display()
+ );
filepath
};
diff --git a/crates/core/tedge_core/tests/plugin_does_not_shutdown.rs b/crates/core/tedge_core/tests/plugin_does_not_shutdown.rs
index f7765ba3..9785bedc 100644
--- a/crates/core/tedge_core/tests/plugin_does_not_shutdown.rs
+++ b/crates/core/tedge_core/tests/plugin_does_not_shutdown.rs
@@ -1,11 +1,11 @@
use async_trait::async_trait;
use futures::future::FutureExt;
+use tedge_api::plugin::PluginExt;
use tedge_api::Plugin;
use tedge_api::PluginBuilder;
use tedge_api::PluginConfiguration;
use tedge_api::PluginDirectory;
use tedge_api::PluginError;
-use tedge_api::plugin::PluginExt;
use tedge_core::TedgeApplication;
pub struct NoShutdownPluginBuilder;
@@ -33,7 +33,8 @@ impl<PD: PluginDirectory> PluginBuilder<PD> for NoShutdownPluginBuilder {
}
fn kind_message_types() -> tedge_api::plugin::HandleTypes
- where Self:Sized
+ where
+ Self: Sized,
{
NoShutdownPlugin::get_handled_types()
}
@@ -52,7 +53,6 @@ impl Plugin for NoShutdownPlugin {
Ok(())
}
-
async fn shutdown(&mut self) -> Result<(), PluginError> {
tracing::info!("Shutdown called");
loop {
@@ -72,11 +72,19 @@ fn test_no_shutdown_plugin() -> Result<(), Box<(dyn std::error::Error + 'static)
let res = rt.block_on(async {
let config_file_path = {
- let dir = std::env::current_exe().unwrap().parent().unwrap().join("../../../");
+ let dir = std::env::current_exe()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("../../../");
let mut name = std::path::PathBuf::from(std::file!());
name.set_extension("toml");
let filepath = dir.join(name);
- assert!(filepath.exists(), "Config file does not exist: {}", filepath.display());
+ assert!(
+ filepath.exists(),
+ "Config file does not exist: {}",
+ filepath.display()
+ );
filepath
};
let (cancel_sender, application) = TedgeApplication::builder()
@@ -88,19 +96,17 @@ fn test_no_shutdown_plugin() -> Result<(), Box<(dyn std::error::Error + 'static)
// send a cancel request to the app after 1 sec
let mut cancel_fut = Box::pin({
- tokio::time::sleep(std::time::Duration::from_secs(1))
- .then(|_| async {
- tracing::info!("Cancelling app now");
- cancel_sender.cancel_app()
- })
+ tokio::time::sleep(std::time::Duration::from_secs(1)).then(|_| async {
+ tracing::info!("Cancelling app now");
+ cancel_sender.cancel_app()
+ })
});
// Abort the test after 5 secs, because it seems not to stop the application
let mut test_abort = Box::pin({
- tokio::time::sleep(std::time::Duration::from_secs(5))
- .then(|_| async {
- tracing::info!("Aborting test");
- })
+ tokio::time::sleep(std::time::Duration::from_secs(5)).then(|_| async {
+ tracing::info!("Aborting test");
+ })
});
let mut cancelled = false;
@@ -136,4 +142,3 @@ fn test_no_shutdown_plugin() -> Result<(), Box<(dyn std::error::Error + 'static)
}
Ok(())
}
-
diff --git a/crates/core/tedge_core/tests/plugin_does_not_support_message.rs b/crates/core/tedge_core/tests/plugin_does_not_support_message.rs
index 1ff19632..ad574782 100644
--- a/crates/core/tedge_core/tests/plugin_does_not_support_message.rs
+++ b/crates/core/tedge_core/tests/plugin_does_not_support_message.rs
@@ -95,9 +95,7 @@ mod sending {
) -> Result<tedge_api::plugin::BuiltPlugin, PluginError> {
tracing::warn!("Going to fetch addresses that do not support the messages I expect");
// this should not work
- let _target_addr = plugin_dir.get_address_for::<SendingMessages>(
- "not_supported"
- )?;
+ let _target_addr = plugin_dir.get_address_for::<SendingMessages>("not_supported")?;
Ok(SendingPlugin {}.finish())
}
@@ -130,8 +128,7 @@ mod sending {
#[derive(Debug)]
pub struct SendingMessage;
- impl tedge_api::plugin::Message for SendingMessage {
- }
+ impl tedge_api::plugin::Message for SendingMessage {}
tedge_api::make_receiver_bundle!(pub struct SendingMessages(SendingMessage));
}
@@ -141,11 +138,19 @@ async fn test_not_supported_message() -> Result<(), Box<(dyn std::error::Error +
let _ = tracing_subscriber::fmt::try_init();
let config_file_path = {
- let dir = std::env::current_exe().unwrap().parent().unwrap().join("../../../");
+ let dir = std::env::current_exe()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("../../../");
let mut name = std::path::PathBuf::from(std::file!());
name.set_extension("toml");
let filepath = dir.join(name);
- assert!(filepath.exists(), "Config file does not exist: {}", filepath.display());
+ assert!(
+ filepath.exists(),
+ "Config file does not exist: {}",
+ filepath.display()
+ );
filepath
};
diff --git a/crates/core/tedge_core/tests/plugin_panic_lifecycle.rs b/crates/core/tedge_core/tests/plugin_panic_lifecycle.rs
index 45deebf3..263c2291 100644
--- a/crates/core/tedge_core/tests/plugin_panic_lifecycle.rs
+++ b/crates/core/tedge_core/tests/plugin_panic_lifecycle.rs
@@ -1,13 +1,13 @@
use async_trait::async_trait;
use futures::future::FutureExt;
use miette::IntoDiagnostic;
+use tedge_api::plugin::HandleTypes;
+use tedge_api::plugin::PluginExt;
use tedge_api::Plugin;
use tedge_api::PluginBuilder;
use tedge_api::PluginConfiguration;
use tedge_api::PluginDirectory;
use tedge_api::PluginError;
-use tedge_api::plugin::HandleTypes;
-use tedge_api::plugin::PluginExt;
use tedge_core::TedgeApplication;
pub struct PanicPluginBuilder;
@@ -48,17 +48,19 @@ impl<PD: PluginDirectory> PluginBuilder<PD> for PanicPluginBuilder {
_cancellation_token: tedge_api::CancellationToken,
_plugin_dir: &PD,
) -> Result<tedge_api::plugin::BuiltPlugin, PluginError> {
- let config: PanicPluginConf = config
- .try_into()
- .into_diagnostic()?;
+ let config: PanicPluginConf = config.try_into().into_diagnostic()?;
tracing::info!("Config = {:?}", config);
- Ok(PanicPlugin { panic_loc: config.panic_location }.finish())
+ Ok(PanicPlugin {
+ panic_loc: config.panic_location,
+ }
+ .finish())
}
fn kind_message_types() -> HandleTypes
- where Self:Sized
+ where
+ Self: Sized,
{
PanicPlugin::get_handled_types()
}
@@ -83,7 +85,6 @@ impl Plugin for PanicPlugin {
Ok(())
}
-
async fn shutdown(&mut self) -> Result<(), PluginError> {
tracing::info!("Shutdown called");
if let PanicLocation::Shutdown = self.panic_loc {
@@ -175,5 +176,3 @@ fn test_setup_panic_plugin() -> Result<(), Box<(dyn std::error::Error + 'static)
}
Ok(())
}
-
-
diff --git a/crates/core/tedge_core/tests/plugin_panics_in_msg_handler.rs b/crates/core/tedge_core/tests/plugin_panics_in_msg_handler.rs
index 4fc7ea4d..ae493103 100644
--- a/crates/core/tedge_core/tests/plugin_panics_in_msg_handler.rs
+++ b/crates/core/tedge_core/tests/plugin_panics_in_msg_handler.rs
@@ -1,15 +1,15 @@
use async_trait::async_trait;
use futures::future::FutureExt;
+use tedge_api::address::ReplySenderFor;
+use tedge_api::plugin::Handle;
+use tedge_api::plugin::Message;
+use tedge_api::plugin::PluginExt;
use tedge_api::Address;
use tedge_api::Plugin;
use tedge_api::PluginBuilder;
use tedge_api::PluginConfiguration;
use tedge_api::PluginDirectory;
use tedge_api::PluginError;
-use tedge_api::address::ReplySenderFor;
-use tedge_api::plugin::Handle;
-use tedge_api::plugin::Message;
-use tedge_api::plugin::PluginExt;
use tedge_core::TedgeApplication;
pub struct HandlePanicPluginBuilder;
@@ -38,7 +38,8 @@ impl<PD: PluginDirectory> PluginBuilder<PD> for HandlePanicPluginBuilder {
}
fn kind_message_types() -> tedge_api::plugin::HandleTypes
- where Self:Sized
+ where
+ Self: Sized,
{
HandlePanicPlugin::get_handled_types()
}
@@ -62,7 +63,6 @@ impl Plugin for HandlePanicPlugin {
Ok(())
}
-
async fn shutdown(&mut self) -> Result<(), PluginError> {
tracing::info!("Shutdown called");
Ok(())
@@ -72,8 +72,7 @@ impl Plugin for HandlePanicPlugin {
#[derive(Debug)]
struct DoPanic;
-impl Message for DoPanic {
-}
+impl Message for DoPanic {}
#[async_trait::async_trait]
impl Handle<DoPanic> for HandlePanicPlugin {
@@ -97,11 +96,19 @@ fn test_handler_panic() -> Result<(), Box<(dyn std::error::Error + 'static)>> {
let res = rt.block_on(async {
let config_file_path = {
- let dir = std::env::current_exe().unwrap().parent().unwrap().join("../../../");
+ let dir = std::env::current_exe()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("../../../");
let mut name = std::path::PathBuf::from(std::file!());
name.set_extension("toml");
let filepath = dir.join(name);
- assert!(filepath.exists(), "Config file does not exist: {}", filepath.display());
+ assert!(
+ filepath.exists(),
+ "Config file does not exist: {}",
+ filepath.display()
+ );
filepath
};
@@ -114,19 +121,17 @@ fn test_handler_panic() -> Result<(), Box<(dyn std::error::Error + 'static)>> {
// send a cancel request to the app after 1 sec
let mut cancel_fut = Box::pin({
- tokio::time::sleep(std::time::Duration::from_secs(1))
- .then(|_| async {
- tracing::info!("Cancelling app now");
- cancel_sender.cancel_app()
- })
+ tokio::time::sleep(std::time::Duration::from_secs(1)).then(|_| async {
+ tracing::info!("Cancelling app now");
+ cancel_sender.cancel_app()
+ })
});
// Abort the test after 5 secs, because it seems not to stop the application
let mut test_abort = Box::pin({
- tokio::time::sleep(std::time::Duration::from_secs(5))
- .then(|_| async {
- tracing::info!("Aborting test");
- })
+ tokio::time::sleep(std::time::Duration::from_secs(5)).then(|_| async {
+ tracing::info!("Aborting test");
+ })
});
let mut cancelled = false;
@@ -162,5 +167,3 @@ fn test_handler_panic() -> Result<(), Box<(dyn std::error::Error + 'static)>> {
}
Ok(())
}
-
-
diff --git a/crates/core/tedge_core/tests/plugin_send_to_self_name.rs b/crates/core/tedge_core/tests/plugin_send_to_self_name.rs
index 3065f5f1..817f5442 100644
--- a/crates/core/tedge_core/tests/plugin_send_to_self_name.rs
+++ b/crates/core/tedge_core/tests/plugin_send_to_self_name.rs
@@ -1,14 +1,14 @@
use async_trait::async_trait;
use futures::future::FutureExt;
+use tedge_api::plugin::HandleTypes;
+use tedge_api::plugin::PluginExt;
+use tedge_api::Address;
use tedge_api::CoreMessages;
use tedge_api::Plugin;
-use tedge_api::Address;
use tedge_api::PluginBuilder;
use tedge_api::PluginConfiguration;
use tedge_api::PluginDirectory;
use tedge_api::PluginError;
-use tedge_api::plugin::HandleTypes;
-use tedge_api::plugin::PluginExt;
use tedge_core::TedgeApplication;
pub struct SelfSendPluginBuilder;
@@ -16,8 +16,7 @@ pub struct SelfSendPluginBuilder;
#[derive(Debug)]
struct Msg;
-impl tedge_api::Message for Msg {
-}
+impl tedge_api::Message for Msg {}
tedge_api::make_receiver_bundle!(struct MsgRecv(Msg));
@@ -47,7 +46,8 @@ impl<PD: PluginDirectory> PluginBuilder<PD> for SelfSendPluginBuilder {
}
fn kind_message_types() -> HandleTypes
- where Self:Sized
+ where
+ Self: Sized,
{
SelfSendPlugin::get_handled_types()
}
@@ -66,11 +66,13 @@ impl Plugin for SelfSendPlugin {
#[allow(unreachable_code)]
async fn start(&mut self) -> Result<(), PluginError> {
tracing::info!("Sending StopCore now");
- self.core_addr.send_and_wait(tedge_api::message::StopCore).await.expect("Sending StopCore failed");
+ self.core_addr
+ .send_and_wait(tedge_api::message::StopCore)
+ .await
+ .expect("Sending StopCore failed");
Ok(())
}
-
async fn shutdown(&mut self) -> Result<(), PluginError> {
Ok(())
}
@@ -78,10 +80,13 @@ impl Plugin for SelfSendPlugin {
#[async_trait]
impl tedge_api::plugin::Handle<Msg> for SelfSendPlugin {
- async fn handle_message(&self, _: Msg, _: tedge_api::address::ReplySenderFor<Msg>) -> Result<(), miette::Error> {
+ async fn handle_message(
+ &self,
+ _: Msg,
+ _: tedge_api::address::ReplySenderFor<Msg>,
+ ) -> Result<(), miette::Error> {
unimplemented!() // will never be called in this test
}
-
}
#[test]
@@ -95,11 +100,19 @@ fn test_send_to_self_via_name_does_work() -> Result<(), Box<(dyn std::error::Err
let res = rt.block_on(async {
let config_file_path = {
- let dir = std::env::current_exe().unwrap().parent().unwrap().join("../../../");
+ let dir = std::env::current_exe()
+ .unwrap()
+ .parent()
+ .unwrap()
+ .join("../../../");
let mut name = std::path::PathBuf::from(std::file!());
name.set_extension("toml");
let filepath = dir.join(name);
- assert!(filepath.exists(), "Config file does not exist: {}", filepath.display());
+ assert!(
+ filepath.exists(),
+ "Config file does not exist: {}",
+ filepath.display()
+ );
filepath
};
@@ -112,19 +125,17 @@ fn test_send_to_self_via_name_does_work() -> Result<(), Box<(dyn std::error::Err
// send a cancel request to the app after 1 sec
let mut cancel_fut = Box::pin({
- tokio::time::sleep(std::time::Duration::from_secs(1))
- .then(|_| async {
- tracing::info!("Cancelling app now");