diff --git a/src/section_runner.rs b/src/section_runner.rs index 1b9fffb..14e07b1 100644 --- a/src/section_runner.rs +++ b/src/section_runner.rs @@ -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; + } }