Add test for SectionRunner pause/unpause #3

Merged
amikhalev merged 3 commits from section-runner-pause into master 2020-08-19 02:57:39 +00:00
Showing only changes of commit 42cce06d68 - Show all commits

View File

@ -487,4 +487,68 @@ mod test {
runner.quit().await.unwrap();
tokio::task::yield_now().await;
}
#[tokio::test]
async fn test_pause() {
let (sections, interface) = make_sections_and_interface();
let mut runner = SectionRunner::new(interface.clone());
let _run1 = runner
.queue_run(sections[1].clone(), Duration::from_secs(10))
.await
.unwrap();
let run2 = runner
.queue_run(sections[0].clone(), Duration::from_secs(10))
.await
.unwrap();
let _run3 = runner
.queue_run(sections[1].clone(), Duration::from_secs(10))
.await
.unwrap();
pause();
advance(Duration::from_secs(1)).await;
assert_section_states(&interface, &[false, true]);
runner.pause().await.unwrap();
tokio::task::yield_now().await;
assert_section_states(&interface, &[false, false]);
advance(Duration::from_secs(10)).await;
assert_section_states(&interface, &[false, false]);
runner.unpause().await.unwrap();
tokio::task::yield_now().await;
assert_section_states(&interface, &[false, true]);
advance(Duration::from_secs(8)).await;
assert_section_states(&interface, &[false, true]);
advance(Duration::from_secs(2)).await;
assert_section_states(&interface, &[true, false]);
runner.pause().await.unwrap();
tokio::task::yield_now().await;
assert_section_states(&interface, &[false, false]);
// cancel paused run
runner.cancel_run(run2).await.unwrap();
tokio::task::yield_now().await;
assert_section_states(&interface, &[false, false]);
runner.unpause().await.unwrap();
tokio::task::yield_now().await;
assert_section_states(&interface, &[false, true]);
advance(Duration::from_secs(10)).await;
assert_section_states(&interface, &[false, false]);
resume();
runner.quit().await.unwrap();
tokio::task::yield_now().await;
}
}