Skip to content

Commit a1888d2

Browse files
committed
Add benchmark options to tedge mqtt pub
Signed-off-by: Didier Wenzek <didier.wenzek@free.fr>
1 parent 5c16cfc commit a1888d2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

crates/core/tedge/src/cli/mqtt/cli.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ pub enum TEdgeMqttCli {
3030
/// Retain flag
3131
#[clap(short, long = "retain")]
3232
retain: bool,
33+
/// Repeat the message
34+
#[clap(long)]
35+
repeat: Option<u32>,
36+
/// Pause between repeated messages (e.g., 60s, 1h)
37+
#[clap(long, default_value = "1s")]
38+
sleep: SecondsOrHumanTime,
3339
},
3440

3541
/// Subscribe a MQTT topic.
@@ -69,6 +75,8 @@ impl BuildCommand for TEdgeMqttCli {
6975
message,
7076
qos,
7177
retain,
78+
repeat,
79+
sleep,
7280
} => MqttPublishCommand {
7381
host: config.mqtt.client.host.clone(),
7482
port: config.mqtt.client.port.into(),
@@ -80,6 +88,8 @@ impl BuildCommand for TEdgeMqttCli {
8088
ca_file: auth_config.ca_file.clone(),
8189
ca_dir: auth_config.ca_dir,
8290
client_auth_config: auth_config.client,
91+
count: repeat.unwrap_or(1),
92+
sleep: sleep.duration(),
8393
}
8494
.into_boxed(),
8595
TEdgeMqttCli::Sub {

crates/core/tedge/src/cli/mqtt/publish.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub struct MqttPublishCommand {
2222
pub ca_file: Option<Utf8PathBuf>,
2323
pub ca_dir: Option<Utf8PathBuf>,
2424
pub client_auth_config: Option<MqttAuthClientConfig>,
25+
pub count: u32,
26+
pub sleep: std::time::Duration,
2527
}
2628

2729
#[async_trait::async_trait]
@@ -36,7 +38,15 @@ impl Command for MqttPublishCommand {
3638
}
3739

3840
async fn execute(&self, _: TEdgeConfig) -> Result<(), MaybeFancy<anyhow::Error>> {
39-
Ok(publish(self).await?)
41+
let mut i = 0;
42+
loop {
43+
publish(self).await?;
44+
i += 1;
45+
if i == self.count {
46+
return Ok(());
47+
}
48+
tokio::time::sleep(self.sleep).await;
49+
}
4050
}
4151
}
4252

0 commit comments

Comments
 (0)