Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions tests/connection_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,51 @@

#[rstest]
#[tokio::test]
async fn fairness_yields_low_with_time_slice(
queues: (PushQueues<u8>, wireframe::push::PushHandle<u8>),
shutdown_token: CancellationToken,
) {
use std::time::Duration;

use tokio::{sync::oneshot, time::sleep};
Comment on lines +77 to +79
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove redundant imports.

The imports std::time::Duration and tokio::{sync::oneshot, time::sleep} are redundant. Duration and sleep are already imported at the module level (lines 8-9), and oneshot should be imported at the module level for consistency.

-    use std::time::Duration;
-
-    use tokio::{sync::oneshot, time::sleep};

Add oneshot to the existing tokio imports at the module level:

-use tokio::time::{Duration, sleep, timeout};
+use tokio::{sync::oneshot, time::{Duration, sleep, timeout}};
🤖 Prompt for AI Agents
In tests/connection_actor.rs around lines 77 to 79, remove the redundant imports
of std::time::Duration and tokio::{sync::oneshot, time::sleep} since Duration
and sleep are already imported at the module level. Instead, add oneshot to the
existing tokio imports at the module level for consistency and clean up
duplicate imports in this section.


let (queues, handle) = queues;
let fairness = FairnessConfig {
max_high_before_low: 0,
time_slice: Some(Duration::from_millis(10)),
};

let mut actor: ConnectionActor<_, ()> =
ConnectionActor::new(queues, handle.clone(), None, shutdown_token);
actor.set_fairness(fairness);

let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
let mut out = Vec::new();
let _ = actor.run(&mut out).await;
let _ = tx.send(out);
});

handle.push_high_priority(1).await.unwrap();
sleep(Duration::from_millis(5)).await;
handle.push_high_priority(2).await.unwrap();
sleep(Duration::from_millis(15)).await;
handle.push_low_priority(42).await.unwrap();
for n in 3..=5 {
handle.push_high_priority(n).await.unwrap();
}
drop(handle);

let out = rx.await.unwrap();
assert!(out.contains(&42), "Low-priority item was not yielded");
let pos = out.iter().position(|x| *x == 42).unwrap();
assert!(
pos > 0 && pos < out.len() - 1,
"Low-priority item should be yielded in the middle"
);
}

async fn fairness_disabled_processes_all_high_first(

Check failure on line 117 in tests/connection_actor.rs

View workflow job for this annotation

GitHub Actions / build-test

function `fairness_disabled_processes_all_high_first` is never used
queues: (PushQueues<u8>, wireframe::push::PushHandle<u8>),
shutdown_token: CancellationToken,
) {
Expand Down
Loading