|
|
@ -373,6 +373,7 @@ mod test { |
|
|
|
use crate::section_interface::{MockSectionInterface, SectionInterface}; |
|
|
|
use crate::section_interface::{MockSectionInterface, SectionInterface}; |
|
|
|
use crate::{ |
|
|
|
use crate::{ |
|
|
|
model::{Program, ProgramItem, Section}, |
|
|
|
model::{Program, ProgramItem, Section}, |
|
|
|
|
|
|
|
schedule::Schedule, |
|
|
|
trace_listeners::{EventListener, Filters, SpanFilters, SpanListener}, |
|
|
|
trace_listeners::{EventListener, Filters, SpanFilters, SpanListener}, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use im::ordmap; |
|
|
|
use im::ordmap; |
|
|
@ -428,6 +429,17 @@ mod test { |
|
|
|
(sections, sec_runner, interface) |
|
|
|
(sections, sec_runner, interface) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn make_program(num: ProgramId, sequence: Vec<ProgramItem>) -> ProgramRef { |
|
|
|
|
|
|
|
Program { |
|
|
|
|
|
|
|
id: num, |
|
|
|
|
|
|
|
name: format!("Program {}", num), |
|
|
|
|
|
|
|
sequence, |
|
|
|
|
|
|
|
enabled: false, |
|
|
|
|
|
|
|
schedule: Schedule::default(), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.into() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[tokio::test] |
|
|
|
#[tokio::test] |
|
|
|
async fn test_run_program() { |
|
|
|
async fn test_run_program() { |
|
|
|
let (sections, mut sec_runner, interface) = make_sections_and_runner(); |
|
|
|
let (sections, mut sec_runner, interface) = make_sections_and_runner(); |
|
|
@ -435,10 +447,9 @@ mod test { |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let program: ProgramRef = Program { |
|
|
|
let program = make_program( |
|
|
|
id: 1, |
|
|
|
1, |
|
|
|
name: "Program 1".into(), |
|
|
|
vec![ |
|
|
|
sequence: vec![ |
|
|
|
|
|
|
|
ProgramItem { |
|
|
|
ProgramItem { |
|
|
|
section_id: 1, |
|
|
|
section_id: 1, |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
@ -448,8 +459,7 @@ mod test { |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
|
} |
|
|
|
); |
|
|
|
.into(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
@ -497,25 +507,20 @@ mod test { |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let program1: ProgramRef = Program { |
|
|
|
let program1 = make_program( |
|
|
|
id: 1, |
|
|
|
1, |
|
|
|
name: "Program 1".into(), |
|
|
|
vec![ProgramItem { |
|
|
|
sequence: vec![ProgramItem { |
|
|
|
|
|
|
|
section_id: 3, |
|
|
|
section_id: 3, |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
}], |
|
|
|
}], |
|
|
|
} |
|
|
|
); |
|
|
|
.into(); |
|
|
|
let program2 = make_program( |
|
|
|
let program2: ProgramRef = Program { |
|
|
|
2, |
|
|
|
id: 2, |
|
|
|
vec![ProgramItem { |
|
|
|
name: "Program 2".into(), |
|
|
|
|
|
|
|
sequence: vec![ProgramItem { |
|
|
|
|
|
|
|
section_id: 1, |
|
|
|
section_id: 1, |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
}], |
|
|
|
}], |
|
|
|
} |
|
|
|
); |
|
|
|
.into(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
runner.run_program(program1).await.unwrap(); |
|
|
|
runner.run_program(program1).await.unwrap(); |
|
|
@ -559,12 +564,7 @@ mod test { |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let program: ProgramRef = Program { |
|
|
|
let program = make_program(1, vec![]); |
|
|
|
id: 1, |
|
|
|
|
|
|
|
name: "Program 1".into(), |
|
|
|
|
|
|
|
sequence: vec![], |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.into(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
@ -588,24 +588,20 @@ mod test { |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let program1: ProgramRef = Program { |
|
|
|
let program1 = make_program( |
|
|
|
id: 1, |
|
|
|
1, |
|
|
|
name: "Program 1".into(), |
|
|
|
vec![ProgramItem { |
|
|
|
sequence: vec![ProgramItem { |
|
|
|
|
|
|
|
section_id: 2, |
|
|
|
section_id: 2, |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
}], |
|
|
|
}], |
|
|
|
} |
|
|
|
); |
|
|
|
.into(); |
|
|
|
let program2 = make_program( |
|
|
|
let program2: ProgramRef = Program { |
|
|
|
2, |
|
|
|
id: 2, |
|
|
|
vec![ProgramItem { |
|
|
|
name: "Program 2".into(), |
|
|
|
|
|
|
|
sequence: vec![ProgramItem { |
|
|
|
|
|
|
|
section_id: 2, |
|
|
|
section_id: 2, |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
}], |
|
|
|
}], |
|
|
|
} |
|
|
|
); |
|
|
|
.into(); |
|
|
|
|
|
|
|
let programs = ordmap![ 1 => program1, 2 => program2 ]; |
|
|
|
let programs = ordmap![ 1 => program1, 2 => program2 ]; |
|
|
|
|
|
|
|
|
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
@ -659,10 +655,9 @@ mod test { |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut runner = ProgramRunner::new(sec_runner.clone()); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
let mut prog_events = runner.subscribe().await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let program: ProgramRef = Program { |
|
|
|
let program = make_program( |
|
|
|
id: 1, |
|
|
|
1, |
|
|
|
name: "Program 1".into(), |
|
|
|
vec![ |
|
|
|
sequence: vec![ |
|
|
|
|
|
|
|
ProgramItem { |
|
|
|
ProgramItem { |
|
|
|
section_id: 1, |
|
|
|
section_id: 1, |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
@ -672,8 +667,7 @@ mod test { |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
duration: Duration::from_secs(10), |
|
|
|
}, |
|
|
|
}, |
|
|
|
], |
|
|
|
], |
|
|
|
} |
|
|
|
); |
|
|
|
.into(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
runner.update_sections(sections.clone()).await.unwrap(); |
|
|
|
|
|
|
|
|
|
|
|