Skip to content

Commit 45e8a5c

Browse files
committed
chore: remove uneeded From implementation
1 parent a85d095 commit 45e8a5c

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

agent-control/src/event.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,3 @@ pub enum SubAgentInternalEvent {
5454
AgentHealthInfo(HealthWithStartTime),
5555
AgentVersionInfo(AgentVersion),
5656
}
57-
58-
impl From<HealthWithStartTime> for SubAgentInternalEvent {
59-
fn from(health: HealthWithStartTime) -> Self {
60-
Self::AgentHealthInfo(health)
61-
}
62-
}

agent-control/src/sub_agent/on_host/supervisor.rs

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ pub mod tests {
398398
use crate::health::health_checker::Healthy;
399399
use crate::sub_agent::on_host::command::executable_data::ExecutableData;
400400
use crate::sub_agent::on_host::command::restart_policy::{Backoff, RestartPolicy};
401-
use crate::sub_agent::version::version_checker::AgentVersion;
402401
use std::thread;
403402
use std::time::{Duration, Instant};
404403
use tracing_test::traced_test;
@@ -626,37 +625,36 @@ pub mod tests {
626625
let start_time = SystemTime::now();
627626

628627
// It starts once and restarts 3 times, hence 4 healthy events and a final unhealthy one
629-
let expected_ordered_events: Vec<SubAgentInternalEvent> = {
630-
vec![
631-
HealthWithStartTime::new(Healthy::default().into(), start_time).into(),
632-
HealthWithStartTime::new(Healthy::default().into(), start_time).into(),
633-
HealthWithStartTime::new(Healthy::default().into(), start_time).into(),
634-
HealthWithStartTime::new(Healthy::default().into(), start_time).into(),
635-
HealthWithStartTime::new(
636-
Unhealthy::new(
637-
String::default(),
638-
"supervisor exceeded its defined restart policy".to_string(),
639-
)
640-
.into(),
641-
start_time,
628+
let expected_ordered_events: Vec<SubAgentInternalEvent> = [
629+
HealthWithStartTime::new(Healthy::default().into(), start_time),
630+
HealthWithStartTime::new(Healthy::default().into(), start_time),
631+
HealthWithStartTime::new(Healthy::default().into(), start_time),
632+
HealthWithStartTime::new(Healthy::default().into(), start_time),
633+
HealthWithStartTime::new(
634+
Unhealthy::new(
635+
String::default(),
636+
"supervisor exceeded its defined restart policy".to_string(),
642637
)
643638
.into(),
644-
]
645-
};
639+
start_time,
640+
),
641+
]
642+
.into_iter()
643+
.map(SubAgentInternalEvent::AgentHealthInfo)
644+
.collect();
646645

647646
let actual_ordered_events = sub_agent_internal_consumer
648647
.as_ref()
649648
.iter()
650-
.map(|event| match event {
651-
SubAgentInternalEvent::AgentHealthInfo(health) => {
652-
HealthWithStartTime::new(health.into(), start_time).into()
653-
}
654-
SubAgentInternalEvent::StopRequested => SubAgentInternalEvent::StopRequested,
655-
SubAgentInternalEvent::AgentVersionInfo(agent_id) => {
656-
SubAgentInternalEvent::AgentVersionInfo(AgentVersion::new(
657-
agent_id.version().to_string(),
658-
agent_id.opamp_field().to_string(),
649+
.map(|event| {
650+
// Patch start_time for health events to allow comparison
651+
if let SubAgentInternalEvent::AgentHealthInfo(health) = event {
652+
SubAgentInternalEvent::AgentHealthInfo(HealthWithStartTime::new(
653+
health.into(),
654+
start_time,
659655
))
656+
} else {
657+
event
660658
}
661659
})
662660
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)