Skip to content

Commit

Permalink
fix: send fragment updates before changing to successful state for fi…
Browse files Browse the repository at this point in the history
…rmware and software update

Signed-off-by: Krzysztof Piotrowski <krzysztof.piotrowski@inetum.com>
  • Loading branch information
Ruadhri17 committed Feb 5, 2025
1 parent c97a120 commit b603f85
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl OperationContext {
.with_qos(QoS::AtLeastOnce);

Ok(OperationOutcome::Finished {
messages: vec![c8y_notification, twin_metadata],
messages: vec![twin_metadata, c8y_notification],
})
}
CommandStatus::Failed { reason } => Err(anyhow::anyhow!(reason).into()),
Expand Down Expand Up @@ -530,11 +530,11 @@ mod tests {
assert_received_contains_str(
&mut mqtt,
[
("c8y/s/us", "503,c8y_Firmware"), // SmartREST successful
(
"te/device/main///twin/firmware",
r#"{"name":"myFirmware","version":"1.0","url":"http://www.my.url"}"#,
), // Twin firmware metadata
("c8y/s/us", "503,c8y_Firmware"), // SmartREST successful
("te/device/main///cmd/firmware_update/c8y-mapper-1234", ""), // Clear cmd
],
)
Expand Down Expand Up @@ -579,11 +579,11 @@ mod tests {
assert_received_contains_str(
&mut mqtt,
[
("c8y/s/us/test-device:device:child1", "503,c8y_Firmware"), // SmartREST successful
(
"te/device/child1///twin/firmware",
r#"{"name":"myFirmware","version":"1.0","url":"http://www.my.url"}"#,
), // Twin firmware metadata
("c8y/s/us/test-device:device:child1", "503,c8y_Firmware"), // SmartREST successful
("te/device/child1///cmd/firmware_update/c8y-mapper-1234", ""), // Clear cmd
],
)
Expand Down Expand Up @@ -623,11 +623,11 @@ mod tests {
assert_received_contains_str(
&mut mqtt,
[
("c8y/s/us", "506,1234"), // SmartREST successful
(
"te/device/main///twin/firmware",
r#"{"name":"myFirmware","version":"1.0","url":"http://www.my.url"}"#,
), // Twin firmware metadata
("c8y/s/us", "506,1234"), // SmartREST successful
("te/device/main///cmd/firmware_update/c8y-mapper-1234", ""), // Clear cmd
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl OperationContext {

Ok(OperationOutcome::Finished {
messages: vec![
MqttMessage::new(topic, smartrest_set_operation),
self.request_software_list(&target.topic_id),
MqttMessage::new(topic, smartrest_set_operation),
],
})
}
Expand All @@ -64,8 +64,8 @@ impl OperationContext {

Ok(OperationOutcome::Finished {
messages: vec![
MqttMessage::new(topic, smartrest_set_operation),
self.request_software_list(&target.topic_id),
MqttMessage::new(topic, smartrest_set_operation),
],
})
}
Expand Down Expand Up @@ -197,9 +197,6 @@ mod tests {
.await
.expect("Send failed");

// Expect `503` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
assert_received_contains_str(&mut mqtt, [("c8y/s/us", "503,c8y_SoftwareUpdate")]).await;

// An updated list of software is requested
assert_received_contains_str(
&mut mqtt,
Expand All @@ -210,6 +207,9 @@ mod tests {
)
.await;

// Expect `503` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
assert_received_contains_str(&mut mqtt, [("c8y/s/us", "503,c8y_SoftwareUpdate")]).await;

// The successful state is cleared
assert_received_contains_str(
&mut mqtt,
Expand Down Expand Up @@ -254,9 +254,6 @@ mod tests {
.await
.expect("Send failed");

// Expect `506` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
assert_received_contains_str(&mut mqtt, [("c8y/s/us", "506,123")]).await;

// An updated list of software is requested
assert_received_contains_str(
&mut mqtt,
Expand All @@ -267,6 +264,9 @@ mod tests {
)
.await;

// Expect `506` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
assert_received_contains_str(&mut mqtt, [("c8y/s/us", "506,123")]).await;

// The successful state is cleared
assert_received_contains_str(
&mut mqtt,
Expand Down Expand Up @@ -294,22 +294,22 @@ mod tests {
.await
.expect("Send failed");

// `502` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
// An updated list of software is requested
assert_received_contains_str(
&mut mqtt,
[(
"c8y/s/us",
"502,c8y_SoftwareUpdate,Partial failure: Couldn't install collectd and nginx",
"te/device/main///cmd/software_list/+",
r#"{"status":"init"}"#,
)],
)
.await;

// An updated list of software is requested
// `502` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
assert_received_contains_str(
&mut mqtt,
[(
"te/device/main///cmd/software_list/+",
r#"{"status":"init"}"#,
"c8y/s/us",
"502,c8y_SoftwareUpdate,Partial failure: Couldn't install collectd and nginx",
)],
)
.await;
Expand Down Expand Up @@ -345,22 +345,22 @@ mod tests {
.await
.expect("Send failed");

// `505` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
// An updated list of software is requested
assert_received_contains_str(
&mut mqtt,
[(
"c8y/s/us",
"505,123,Partial failure: Couldn't install collectd and nginx",
"te/device/main///cmd/software_list/+",
r#"{"status":"init"}"#,
)],
)
.await;

// An updated list of software is requested
// `505` messages with correct payload have been received on `c8y/s/us`, if no msg received for the timeout the test fails.
assert_received_contains_str(
&mut mqtt,
[(
"te/device/main///cmd/software_list/+",
r#"{"status":"init"}"#,
"c8y/s/us",
"505,123,Partial failure: Couldn't install collectd and nginx",
)],
)
.await;
Expand Down

0 comments on commit b603f85

Please sign in to comment.