Skip to content

Commit

Permalink
explain start_paused stuff better
Browse files Browse the repository at this point in the history
  • Loading branch information
problame committed Oct 29, 2024
1 parent d1f7b4e commit c7f1ca3
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tokio-epoll-uring/src/system/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ async fn test_write() {
}

/// Scenario: More tasks than slots; each tasks `.await`s one operation at a time.
///
/// NB: In this test, we use the pattern of `select! { ..., sleep(2 seconds) }` to drive op futures
/// to the point where they are enqueued and occupy a slot. This will become flaky if that takes
/// more than 2 seconds. A more deterministic way to do it would be to use
/// #[tokio::test(start_paused=true)].
#[tokio::test]
async fn test_slot_exhaustion_behavior_when_op_future_gets_dropped() {
let system = System::launch().await.unwrap();
Expand All @@ -334,9 +339,9 @@ async fn test_slot_exhaustion_behavior_when_op_future_gets_dropped() {
tokio::select! {
biased; // to ensure we poll system.read() before notifying the test task
_ = &mut fut => {
unreachable!()
unreachable!("timerfd only fires in far future")
}
_ = futures::future::ready(()) => { }
_ = tokio::time::sleep(Duration::from_secs(2)) => { }
}
tx.send(()).expect("test bug");
tokio::select! {
Expand All @@ -362,8 +367,7 @@ async fn test_slot_exhaustion_behavior_when_op_future_gets_dropped() {

// the slots are still blocked on the timerfd
// TODO: assert that directly
// assert it by starting a new read, it will enqueue
// TODO: use start_paused=true for this test, requires tokio upgrade
// assert it by starting a new read and check that that read will be Pending forever
let fire_in = Duration::from_secs(1);
let fd = timerfd::oneshot(fire_in);
tokio::time::sleep(2 * fire_in).await;
Expand All @@ -374,7 +378,7 @@ async fn test_slot_exhaustion_behavior_when_op_future_gets_dropped() {
_ = &mut fut => {
panic!("future shouldn't be ready because all slots are still used")
}
_ = futures::future::ready(()) => { }
_ = tokio::time::sleep(Duration::from_secs(2)) => { }
}

// unblock the tasks by firing their timerfds sooner, otherwise shutdown hangs forever
Expand All @@ -395,6 +399,11 @@ async fn test_slot_exhaustion_behavior_when_op_future_gets_dropped() {
///
/// The current behavior is that the operation waits for a slot to
/// become available, i.e., it never completes.
///
/// NB: In this test, we use the pattern of `select! { ..., sleep(2 seconds) }` to drive op futures
/// to the point where they are enqueued and occupy a slot. This will become flaky if that takes
/// more than 2 seconds. A more deterministic way to do it would be to use
/// #[tokio::test(start_paused=true)].
#[tokio::test]
async fn test_slot_exhaustion_behavior_when_op_completes_but_future_does_not_get_polled() {
let system = Arc::new(System::launch().await.unwrap());
Expand Down Expand Up @@ -422,7 +431,6 @@ async fn test_slot_exhaustion_behavior_when_op_completes_but_future_does_not_get
res = &mut nop => {
panic!("nop shouldn't be able to get a slot because all slots are already used: {res:?}")
}
// TODO: use start_paused=true to de-flake this test
_ = tokio::time::sleep(Duration::from_secs(2)) => { }
}

Expand All @@ -437,7 +445,6 @@ async fn test_slot_exhaustion_behavior_when_op_completes_but_future_does_not_get
res = &mut nop => {
panic!("nop shouldn't be able to get a slot because all slots are still used: {res:?}")
}
// TODO: use start_paused=true to de-flake this test
_ = tokio::time::sleep(Duration::from_secs(2)) => { }
}

Expand Down

0 comments on commit c7f1ca3

Please sign in to comment.