|
|
@ -17,7 +17,7 @@ use tokio::{ |
|
|
|
}; |
|
|
|
}; |
|
|
|
use tracing::{debug, trace, trace_span, warn}; |
|
|
|
use tracing::{debug, trace, trace_span, warn}; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)] |
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)] |
|
|
|
pub struct SectionRunHandle(i32); |
|
|
|
pub struct SectionRunHandle(i32); |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
@ -44,13 +44,13 @@ enum RunnerMsg { |
|
|
|
Subscribe(oneshot::Sender<SectionEventRecv>), |
|
|
|
Subscribe(oneshot::Sender<SectionEventRecv>), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, PartialEq)] |
|
|
|
#[derive(Clone, Debug)] |
|
|
|
pub enum SectionEvent { |
|
|
|
pub enum SectionEvent { |
|
|
|
RunStart(SectionRunHandle), |
|
|
|
RunStart(SectionRunHandle, SectionRef), |
|
|
|
RunFinish(SectionRunHandle), |
|
|
|
RunFinish(SectionRunHandle, SectionRef), |
|
|
|
RunPause(SectionRunHandle), |
|
|
|
RunPause(SectionRunHandle, SectionRef), |
|
|
|
RunUnpause(SectionRunHandle), |
|
|
|
RunUnpause(SectionRunHandle, SectionRef), |
|
|
|
RunCancel(SectionRunHandle), |
|
|
|
RunCancel(SectionRunHandle, SectionRef), |
|
|
|
RunnerPause, |
|
|
|
RunnerPause, |
|
|
|
RunnerUnpause, |
|
|
|
RunnerUnpause, |
|
|
|
} |
|
|
|
} |
|
|
@ -176,7 +176,10 @@ impl RunnerTask { |
|
|
|
run.state = Running { |
|
|
|
run.state = Running { |
|
|
|
start_time: Instant::now(), |
|
|
|
start_time: Instant::now(), |
|
|
|
}; |
|
|
|
}; |
|
|
|
self.send_event(SectionEvent::RunStart(run.handle.clone())); |
|
|
|
self.send_event(SectionEvent::RunStart( |
|
|
|
|
|
|
|
run.handle.clone(), |
|
|
|
|
|
|
|
run.section.clone(), |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn finish_run(&mut self, run: &mut Arc<SecRun>) { |
|
|
|
fn finish_run(&mut self, run: &mut Arc<SecRun>) { |
|
|
@ -186,7 +189,10 @@ impl RunnerTask { |
|
|
|
self.interface |
|
|
|
self.interface |
|
|
|
.set_section_state(run.section.interface_id, false); |
|
|
|
.set_section_state(run.section.interface_id, false); |
|
|
|
run.state = SecRunState::Finished; |
|
|
|
run.state = SecRunState::Finished; |
|
|
|
self.send_event(SectionEvent::RunFinish(run.handle.clone())); |
|
|
|
self.send_event(SectionEvent::RunFinish( |
|
|
|
|
|
|
|
run.handle.clone(), |
|
|
|
|
|
|
|
run.section.clone(), |
|
|
|
|
|
|
|
)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
warn!( |
|
|
|
warn!( |
|
|
|
section_id = run.section.id, |
|
|
|
section_id = run.section.id, |
|
|
@ -204,7 +210,10 @@ impl RunnerTask { |
|
|
|
.set_section_state(run.section.interface_id, false); |
|
|
|
.set_section_state(run.section.interface_id, false); |
|
|
|
} |
|
|
|
} |
|
|
|
run.state = SecRunState::Cancelled; |
|
|
|
run.state = SecRunState::Cancelled; |
|
|
|
self.send_event(SectionEvent::RunCancel(run.handle.clone())); |
|
|
|
self.send_event(SectionEvent::RunCancel( |
|
|
|
|
|
|
|
run.handle.clone(), |
|
|
|
|
|
|
|
run.section.clone(), |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn pause_run(&mut self, run: &mut Arc<SecRun>) { |
|
|
|
fn pause_run(&mut self, run: &mut Arc<SecRun>) { |
|
|
@ -232,7 +241,10 @@ impl RunnerTask { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
run.state = new_state; |
|
|
|
run.state = new_state; |
|
|
|
self.send_event(SectionEvent::RunPause(run.handle.clone())); |
|
|
|
self.send_event(SectionEvent::RunPause( |
|
|
|
|
|
|
|
run.handle.clone(), |
|
|
|
|
|
|
|
run.section.clone(), |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn unpause_run(&mut self, run: &mut Arc<SecRun>) { |
|
|
|
fn unpause_run(&mut self, run: &mut Arc<SecRun>) { |
|
|
@ -251,7 +263,10 @@ impl RunnerTask { |
|
|
|
}; |
|
|
|
}; |
|
|
|
let ran_for = pause_time - start_time; |
|
|
|
let ran_for = pause_time - start_time; |
|
|
|
run.duration -= ran_for; |
|
|
|
run.duration -= ran_for; |
|
|
|
self.send_event(SectionEvent::RunUnpause(run.handle.clone())); |
|
|
|
self.send_event(SectionEvent::RunUnpause( |
|
|
|
|
|
|
|
run.handle.clone(), |
|
|
|
|
|
|
|
run.section.clone(), |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
Waiting | Finished | Cancelled | Running { .. } => { |
|
|
|
Waiting | Finished | Cancelled | Running { .. } => { |
|
|
|
warn!( |
|
|
|
warn!( |
|
|
@ -467,6 +482,7 @@ mod test { |
|
|
|
model::{Section, Sections}, |
|
|
|
model::{Section, Sections}, |
|
|
|
trace_listeners::{EventListener, Filters, SpanFilters, SpanListener}, |
|
|
|
trace_listeners::{EventListener, Filters, SpanFilters, SpanListener}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
use assert_matches::assert_matches; |
|
|
|
use im::ordmap; |
|
|
|
use im::ordmap; |
|
|
|
use tracing_subscriber::prelude::*; |
|
|
|
use tracing_subscriber::prelude::*; |
|
|
|
|
|
|
|
|
|
|
@ -732,59 +748,39 @@ mod test { |
|
|
|
.await |
|
|
|
.await |
|
|
|
.unwrap(); |
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
assert_eq!( |
|
|
|
assert_matches!( |
|
|
|
event_recv.recv().await, |
|
|
|
event_recv.recv().await, |
|
|
|
Ok(SectionEvent::RunStart(run1.clone())) |
|
|
|
Ok(SectionEvent::RunStart(handle, _)) |
|
|
|
|
|
|
|
if handle == run1 |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
runner.pause().await.unwrap(); |
|
|
|
runner.pause().await.unwrap(); |
|
|
|
assert_eq!(event_recv.recv().await, Ok(SectionEvent::RunnerPause)); |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunnerPause)); |
|
|
|
assert_eq!( |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunPause(handle, _)) if handle == run1); |
|
|
|
event_recv.recv().await, |
|
|
|
|
|
|
|
Ok(SectionEvent::RunPause(run1.clone())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.unpause().await.unwrap(); |
|
|
|
runner.unpause().await.unwrap(); |
|
|
|
assert_eq!(event_recv.recv().await, Ok(SectionEvent::RunnerUnpause)); |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunnerUnpause)); |
|
|
|
assert_eq!( |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunUnpause(handle, _)) if handle == run1); |
|
|
|
event_recv.recv().await, |
|
|
|
|
|
|
|
Ok(SectionEvent::RunUnpause(run1.clone())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
advance(Duration::from_secs(11)).await; |
|
|
|
advance(Duration::from_secs(11)).await; |
|
|
|
assert_eq!(event_recv.recv().await, Ok(SectionEvent::RunFinish(run1))); |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunFinish(handle, _)) if handle == run1); |
|
|
|
assert_eq!( |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunStart(handle, _)) if handle == run2); |
|
|
|
event_recv.recv().await, |
|
|
|
|
|
|
|
Ok(SectionEvent::RunStart(run2.clone())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.pause().await.unwrap(); |
|
|
|
runner.pause().await.unwrap(); |
|
|
|
assert_eq!(event_recv.recv().await, Ok(SectionEvent::RunnerPause)); |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunnerPause)); |
|
|
|
assert_eq!( |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunPause(handle, _)) if handle == run2); |
|
|
|
event_recv.recv().await, |
|
|
|
|
|
|
|
Ok(SectionEvent::RunPause(run2.clone())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// cancel paused run
|
|
|
|
// cancel paused run
|
|
|
|
runner.cancel_run(run2.clone()).await.unwrap(); |
|
|
|
runner.cancel_run(run2.clone()).await.unwrap(); |
|
|
|
assert_eq!( |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunCancel(handle, _)) if handle == run2); |
|
|
|
event_recv.recv().await, |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunPause(handle, _)) if handle == run3); |
|
|
|
Ok(SectionEvent::RunCancel(run2.clone())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
assert_eq!( |
|
|
|
|
|
|
|
event_recv.recv().await, |
|
|
|
|
|
|
|
Ok(SectionEvent::RunPause(run3.clone())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.unpause().await.unwrap(); |
|
|
|
runner.unpause().await.unwrap(); |
|
|
|
assert_eq!(event_recv.recv().await, Ok(SectionEvent::RunnerUnpause)); |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunnerUnpause)); |
|
|
|
assert_eq!( |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunUnpause(handle, _)) if handle == run3); |
|
|
|
event_recv.recv().await, |
|
|
|
|
|
|
|
Ok(SectionEvent::RunUnpause(run3.clone())) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
advance(Duration::from_secs(11)).await; |
|
|
|
advance(Duration::from_secs(11)).await; |
|
|
|
assert_eq!(event_recv.recv().await, Ok(SectionEvent::RunFinish(run3))); |
|
|
|
assert_matches!(event_recv.recv().await, Ok(SectionEvent::RunFinish(handle, _)) if handle == run3); |
|
|
|
|
|
|
|
|
|
|
|
runner.quit().await.unwrap(); |
|
|
|
runner.quit().await.unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|