Browse Source

Fix test usage of `tokio::time::advance`

pull/3/head
Alex Mikhalev 4 years ago
parent
commit
4cf93a9568
  1. 38
      src/section_runner.rs

38
src/section_runner.rs

@ -442,8 +442,10 @@ mod test {
async fn advance(dur: Duration) { async fn advance(dur: Duration) {
// HACK: advance should really be enough, but we need another yield_now // HACK: advance should really be enough, but we need another yield_now
tokio::time::pause();
tokio::time::advance(dur).await; tokio::time::advance(dur).await;
tokio::task::yield_now().await; tokio::task::yield_now().await;
tokio::time::resume();
} }
#[tokio::test] #[tokio::test]
@ -461,12 +463,9 @@ mod test {
tokio::task::yield_now().await; tokio::task::yield_now().await;
pause();
advance(Duration::from_secs(1)).await;
assert_section_states(&interface, &[true, false]); assert_section_states(&interface, &[true, false]);
advance(Duration::from_secs(10)).await; advance(Duration::from_secs(11)).await;
assert_section_states(&interface, &[false, false]); assert_section_states(&interface, &[false, false]);
@ -481,11 +480,11 @@ mod test {
.await .await
.unwrap(); .unwrap();
advance(Duration::from_secs(1)).await; tokio::task::yield_now().await;
assert_section_states(&interface, &[false, true]); assert_section_states(&interface, &[false, true]);
advance(Duration::from_secs(10)).await; advance(Duration::from_secs(11)).await;
assert_section_states(&interface, &[true, false]); assert_section_states(&interface, &[true, false]);
@ -493,8 +492,6 @@ mod test {
assert_section_states(&interface, &[false, false]); assert_section_states(&interface, &[false, false]);
resume();
runner.quit().await.unwrap(); runner.quit().await.unwrap();
tokio::task::yield_now().await; tokio::task::yield_now().await;
} }
@ -519,9 +516,7 @@ mod test {
.await .await
.unwrap(); .unwrap();
pause(); tokio::task::yield_now().await;
advance(Duration::from_secs(1)).await;
assert_section_states(&interface, &[false, true]); assert_section_states(&interface, &[false, true]);
@ -531,12 +526,10 @@ mod test {
assert_section_states(&interface, &[true, false]); assert_section_states(&interface, &[true, false]);
runner.cancel_run(run3).await.unwrap(); runner.cancel_run(run3).await.unwrap();
advance(Duration::from_secs(10)).await; advance(Duration::from_secs(11)).await;
assert_section_states(&interface, &[false, false]); assert_section_states(&interface, &[false, false]);
resume();
runner.quit().await.unwrap(); runner.quit().await.unwrap();
tokio::task::yield_now().await; tokio::task::yield_now().await;
} }
@ -561,24 +554,17 @@ mod test {
.await .await
.unwrap(); .unwrap();
pause(); tokio::task::yield_now().await;
advance(Duration::from_secs(1)).await;
assert_section_states(&interface, &[false, true]); assert_section_states(&interface, &[false, true]);
runner.cancel_all().await.unwrap(); runner.cancel_all().await.unwrap();
tokio::task::yield_now().await; tokio::task::yield_now().await;
assert_section_states(&interface, &[false, false]); assert_section_states(&interface, &[false, false]);
runner.cancel_all().await.unwrap(); runner.cancel_all().await.unwrap();
tokio::task::yield_now().await; tokio::task::yield_now().await;
assert_section_states(&interface, &[false, false]); assert_section_states(&interface, &[false, false]);
resume();
runner.quit().await.unwrap(); runner.quit().await.unwrap();
tokio::task::yield_now().await; tokio::task::yield_now().await;
} }
@ -603,9 +589,7 @@ mod test {
.await .await
.unwrap(); .unwrap();
pause(); tokio::task::yield_now().await;
advance(Duration::from_secs(1)).await;
assert_section_states(&interface, &[false, true]); assert_section_states(&interface, &[false, true]);
runner.pause().await.unwrap(); runner.pause().await.unwrap();
@ -638,11 +622,9 @@ mod test {
tokio::task::yield_now().await; tokio::task::yield_now().await;
assert_section_states(&interface, &[false, true]); assert_section_states(&interface, &[false, true]);
advance(Duration::from_secs(10)).await; advance(Duration::from_secs(11)).await;
assert_section_states(&interface, &[false, false]); assert_section_states(&interface, &[false, false]);
resume();
runner.quit().await.unwrap(); runner.quit().await.unwrap();
tokio::task::yield_now().await; tokio::task::yield_now().await;
} }

Loading…
Cancel
Save