Skip to content

Commit

Permalink
fixup! fixup! POC: Can we remove usage of the timer actor?
Browse files Browse the repository at this point in the history
  • Loading branch information
didier-wenzek committed Mar 6, 2024
1 parent 6760c00 commit 2f10f93
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
20 changes: 17 additions & 3 deletions crates/extensions/c8y_firmware_manager/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,16 +771,30 @@ impl FirmwareManagerWorker {
smartrest_request: SmartRestFirmwareRequest,
mut input_receiver: mpsc::Receiver<FirmwareOperationResponse>,
) -> Result<(), FirmwareManagementError> {
let child_id = smartrest_request.device.clone();
let time_limit = self.config.timeout_sec;

// Forward the request to the child device
self.handle_firmware_download_request_child_device(smartrest_request, &operation_id)
.await?;

// Wait for a response of the child device
let mut current_status = None;
loop {
let Some(response) = timeout(self.config.timeout_sec, input_receiver.next()).await? else {
// The main actor is shutting down
return Ok(());
let response = match timeout(time_limit, input_receiver.next()).await {
Ok(Some(response)) => response,
Ok(None) => {
// The main actor is shutting down
return Ok(());
}
Err(_elapsed) => {
// The child device failed to process the request within the time limit
return Err(FirmwareManagementError::FromTimeout {
child_id,
time_limit_sec: time_limit.as_secs(),
operation_id,
});
}
};

// Proceed with the response of the child device
Expand Down
10 changes: 6 additions & 4 deletions crates/extensions/c8y_firmware_manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ pub enum FirmwareManagementError {
err: DownloadError,
},

// FIXME: restore the previous error message:
// "Child device {child_id} did not respond within the timeout interval of {}sec
#[error(transparent)]
FromTimeout(#[from] tokio::time::error::Elapsed),
#[error("Child device {child_id} did not respond within the timeout interval of {time_limit_sec}sec. Operation ID={operation_id}")]
FromTimeout {
child_id: String,
time_limit_sec: u64,
operation_id: String,
},
}

impl From<FirmwareManagementError> for RuntimeError {
Expand Down
15 changes: 0 additions & 15 deletions crates/extensions/c8y_firmware_manager/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,21 +507,6 @@ async fn handle_request_timeout_child_device() -> Result<(), DynError> {
let firmware_update_request = mqtt_message_box.recv().await.unwrap();
let operation_id = get_operation_id_from_firmware_update_request(firmware_update_request);

// Assert the message to start the timer is sent.
let set_timeout_message = timer_message_box.recv().await.unwrap();
assert_eq!(
set_timeout_message.event,
OperationKey::new(CHILD_DEVICE_ID, &operation_id)
);

// Send timeout message.
// FIXME This test is now broken as the actor is no more listening to message timeouts
timer_message_box
.send(Timeout {
event: set_timeout_message.event,
})
.await?;

// Assert EXECUTING SmartREST message, FAILED SmartREST message
let expected_failure_text =
format!("Child device child-device did not respond within the timeout interval of 1sec. Operation ID={operation_id}");
Expand Down

0 comments on commit 2f10f93

Please sign in to comment.