Skip to content

Commit 93a3bb8

Browse files
Merge pull request #3344 from didier-wenzek/test/entity-registration
Testing device registration using random walk
2 parents 4aa0663 + 12717d6 commit 93a3bb8

File tree

15 files changed

+843
-54
lines changed

15 files changed

+843
-54
lines changed

Cargo.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ rand = "0.8"
155155
rcgen = { version = "0.12", features = ["pem", "zeroize"] }
156156
regex = "1.4"
157157
reqwest = { version = "0.12", default-features = false }
158+
ron = "0.8"
158159
rpassword = "5.0"
159160
rstest = "0.16.0"
160161
rumqttc = { git = "https://github.com/jarhodes314/rumqtt", rev = "8c489faf6af910956c97b55587ff3ecb2ac4e96f" }

crates/core/tedge_agent/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ assert-json-diff = { workspace = true }
5858
axum_tls = { workspace = true, features = ["test-helpers"] }
5959
bytes = { workspace = true }
6060
http-body = { workspace = true }
61+
proptest = { workspace = true }
6162
rcgen = { workspace = true }
63+
ron = { workspace = true }
6264
rustls-pemfile = { workspace = true }
6365
tedge_actors = { workspace = true, features = ["test-helpers"] }
6466
tedge_mqtt_ext = { workspace = true, features = ["test-helpers"] }
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc eb284ae3160cf4a071a3ca80175b2c72680b7c8ba19b8d577805ef1317eca2db # shrinks to registrations = tedge mqtt pub -r te/device/a/service/c '{"@parent":"device/a//","@type":"service"}' && tedge mqtt pub -r te/device/a/service/c '{"@parent":"device/a//","@type":"service"}' && tedge mqtt pub -r te/device/ac// '{"@parent":"device/a//","@type":"child-device"}' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/a//","@topic-id":"device/a/service/c","@type":"service","x":"4"}' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/a//","@type":"child-device"}'
8+
cc 6e3a5e19daf6c3a4732a0504822f2164c5d0f49ed5652e1e67c779a23aedbe77 # shrinks to registrations = tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/main/service/a","@type":"service"}' && tedge mqtt pub -r te/device/abc// '{"@parent":"device/ab//","@type":"child-device","z":"0"}' && tedge mqtt pub -r te/device/abc// '{"@parent":"device/ab//","@type":"child-device","z":"8"}' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/a//","@topic-id":"device/a/service/a","@type":"service"}' && tedge mqtt pub -r te/device/abc// '{"@parent":"device/ab//","@type":"child-device","y":"3"}' && tedge mqtt pub -r te/device/ab// '{"@parent":"device/a//","@type":"child-device"}' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/main/service/a","@type":"service"}' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/ab//","@topic-id":"device/abc//","@type":"child-device","y":"7"}' && tedge mqtt pub -r te/device/a// '{"@parent":"device/main//","@type":"child-device"}'
9+
cc aa8e0b76fd3142bf3cd1df1f453a4468defd437111b406887d760f68d84ad5c3 # shrinks to registrations = tedge http delete /tedge/entity-store/v1/entities/device/a// && tedge http delete /tedge/entity-store/v1/entities/device/main/service/a && tedge mqtt pub -r te/device/main/service/a '{"@parent":"device/main//","@type":"service","z":"1"}' && tedge http delete /tedge/entity-store/v1/entities/device/main/service/a && tedge mqtt pub -r te/device/ab// '' && tedge mqtt pub -r te/device/a// '' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/a//","@type":"child-device"}' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/a//","@type":"child-device"}' && tedge mqtt pub -r te/device/a// '{"@parent":"device/main//","@type":"child-device","z":"4"}'
10+
cc 758d928d082b3dcf1091381c5079eb67097a3128d5185923bd25be490af4980d # shrinks to registrations = tedge mqtt pub -r te/device/main/service/b '{"@parent":"device/main//","@type":"service","z":"6"}' && tedge http delete /tedge/entity-store/v1/entities/device/b// && tedge mqtt pub -r te/device/main/service/b '' && tedge mqtt pub -r te/device/main/service/b '' && tedge mqtt pub -r te/device/b// '{"@parent":"device/main//","@type":"child-device","z":"4"}' && tedge mqtt pub -r te/device/b// '' && tedge mqtt pub -r te/device/b// '' && tedge mqtt pub -r te/device/b// '' && tedge mqtt pub -r te/device/b// '{"@parent":"device/main//","@type":"child-device","y":"7"}' && tedge mqtt pub -r te/device/main/service/b ''
11+
cc 8566571d898d3309d89053873256baa6ca3e459ae65f679c95d5883632531e4b # shrinks to registrations = tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/main/service/a","@type":"service","y":"5"}' && tedge mqtt pub -r te/device/main/service/b '{"@parent":"device/main//","@type":"service"}' && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/a//","@topic-id":"device/ac//","@type":"child-device"}' && tedge mqtt pub -r te/device/ac// '{"@parent":"device/a//","@type":"child-device"}' && tedge http delete /tedge/entity-store/v1/entities/device/ac// && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/a//","@type":"child-device","z":"0"}' && tedge http delete /tedge/entity-store/v1/entities/device/a// && tedge http delete /tedge/entity-store/v1/entities/device/main/service/a && tedge http post /tedge/entity-store/v1/entities '{"@parent":"device/main//","@topic-id":"device/a//","@type":"child-device","x":"5"}'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
pub(crate) mod server;
2+
3+
#[cfg(test)]
4+
mod tests;

crates/core/tedge_agent/src/entity_manager/server.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ impl EntityStoreServer {
5757
entity_auto_register,
5858
}
5959
}
60+
61+
#[cfg(test)]
62+
pub fn entity_topic_ids(&self) -> impl Iterator<Item = &EntityTopicId> {
63+
self.entity_store.entity_topic_ids()
64+
}
65+
66+
#[cfg(test)]
67+
pub fn get(&self, entity_topic_id: &EntityTopicId) -> Option<&EntityMetadata> {
68+
self.entity_store.get(entity_topic_id)
69+
}
6070
}
6171

6272
#[async_trait]
@@ -100,7 +110,7 @@ impl EntityStoreServer {
100110
async fn process_mqtt_message(&mut self, message: MqttMessage) {
101111
if let Ok((topic_id, channel)) = self.mqtt_schema.entity_channel_of(&message.topic) {
102112
if let Channel::EntityMetadata = channel {
103-
self.process_entity_registration(message);
113+
self.process_entity_registration(topic_id, message).await;
104114
} else {
105115
self.process_entity_data(topic_id).await;
106116
}
@@ -109,9 +119,9 @@ impl EntityStoreServer {
109119
}
110120
}
111121

112-
fn process_entity_registration(&mut self, message: MqttMessage) {
122+
async fn process_entity_registration(&mut self, topic_id: EntityTopicId, message: MqttMessage) {
113123
if message.payload().is_empty() {
114-
// Nothing to do on entity clear messages
124+
let _ = self.deregister_entity(topic_id).await;
115125
return;
116126
}
117127

0 commit comments

Comments
 (0)