Skip to content

Commit

Permalink
metrics: fix worker_steal_count test hanging (tokio-rs#6327)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Feb 5, 2024
1 parent fbdf539 commit 47a5fe3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions tokio/tests/rt_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn worker_steal_count() {
// We use a blocking channel to backup one worker thread.
use std::sync::mpsc::channel;

let rt = threaded();
let rt = threaded_no_lifo();
let metrics = rt.metrics();

rt.block_on(async {
Expand All @@ -190,14 +190,12 @@ fn worker_steal_count() {
// Move to the runtime.
tokio::spawn(async move {
// Spawn the task that sends to the channel
//
// Since the lifo slot is disabled, this task is stealable.
tokio::spawn(async move {
tx.send(()).unwrap();
});

// Spawn a task that bumps the previous task out of the "next
// scheduled" slot.
tokio::spawn(async {});

// Blocking receive on the channel.
rx.recv().unwrap();
})
Expand Down Expand Up @@ -729,6 +727,15 @@ fn threaded() -> Runtime {
.unwrap()
}

fn threaded_no_lifo() -> Runtime {
tokio::runtime::Builder::new_multi_thread()
.worker_threads(2)
.disable_lifo_slot()
.enable_all()
.build()
.unwrap()
}

fn us(n: u64) -> Duration {
Duration::from_micros(n)
}

0 comments on commit 47a5fe3

Please sign in to comment.