mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
rt: fix flaky test test_disable_lifo_slot
(#6043)
This commit is contained in:
parent
0700d6a7cd
commit
310adf7ca6
@ -746,12 +746,34 @@ mod unstable {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_disable_lifo_slot() {
|
fn test_disable_lifo_slot() {
|
||||||
|
use std::sync::mpsc::{channel, RecvTimeoutError};
|
||||||
|
|
||||||
let rt = runtime::Builder::new_multi_thread()
|
let rt = runtime::Builder::new_multi_thread()
|
||||||
.disable_lifo_slot()
|
.disable_lifo_slot()
|
||||||
.worker_threads(2)
|
.worker_threads(2)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
// Spawn a background thread to poke the runtime periodically.
|
||||||
|
//
|
||||||
|
// This is necessary because we may end up triggering the issue in:
|
||||||
|
// <https://github.com/tokio-rs/tokio/issues/4730>
|
||||||
|
//
|
||||||
|
// Spawning a task will wake up the second worker, which will then steal
|
||||||
|
// the task. However, the steal will fail if the task is in the LIFO
|
||||||
|
// slot, because the LIFO slot cannot be stolen.
|
||||||
|
//
|
||||||
|
// Note that this only happens rarely. Most of the time, this thread is
|
||||||
|
// not necessary.
|
||||||
|
let (kill_bg_thread, recv) = channel::<()>();
|
||||||
|
let handle = rt.handle().clone();
|
||||||
|
let bg_thread = std::thread::spawn(move || {
|
||||||
|
let one_sec = std::time::Duration::from_secs(1);
|
||||||
|
while recv.recv_timeout(one_sec) == Err(RecvTimeoutError::Timeout) {
|
||||||
|
handle.spawn(async {});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
tokio::spawn(async {
|
tokio::spawn(async {
|
||||||
// Spawn another task and block the thread until completion. If the LIFO slot
|
// Spawn another task and block the thread until completion. If the LIFO slot
|
||||||
@ -760,7 +782,10 @@ mod unstable {
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
})
|
});
|
||||||
|
|
||||||
|
drop(kill_bg_thread);
|
||||||
|
bg_thread.join().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user