Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ R-loom-multi-thread:
- tokio/src/runtime/scheduler/multi_thread/**
- tokio/src/runtime/task/*
- tokio/src/runtime/task/**

R-loom-util-sync:
- tokio-util/src/sync/*
- tokio-util/src/sync/**/*
Comment on lines +24 to +25
Copy link
Member

@ADD-SP ADD-SP Oct 8, 2025

Choose a reason for hiding this comment

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

Suggested change
- tokio-util/src/sync/*
- tokio-util/src/sync/**/*
- tokio-util/src/*
- tokio-util/src/**/*

See #7644 (comment).

16 changes: 16 additions & 0 deletions .github/workflows/loom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,19 @@ jobs:
working-directory: tokio
env:
SCOPE: ${{ matrix.scope }}

loom-util-sync:
name: loom tokio-util::sync
# base_ref is null when it's not a pull request
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-util-sync') || (github.base_ref == null))
Comment on lines +100 to +102
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
name: loom tokio-util::sync
# base_ref is null when it's not a pull request
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-util-sync') || (github.base_ref == null))
name: loom tokio-util::sync
# base_ref is null when it's not a pull request
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-util') || (github.base_ref == null))

Since there is no many loom tests in tokio-util, it should be ok to enable all tests on CI for now.

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Install Rust ${{ env.rust_stable }}
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.rust_stable }}
- uses: Swatinem/rust-cache@v2
- name: run tests
run: cargo test --lib --release --features full -- --nocapture sync::tests
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
run: cargo test --lib --release --features full -- --nocapture sync::tests
run: cargo test --lib --release --features full -- --nocapture

#[cfg(test)]
mod tests {
use super::*;
use tokio::io::{repeat, AsyncReadExt, Repeat};
use tokio_stream::{once, Once, StreamExt};
#[tokio::test]
async fn either_is_stream() {
let mut either: Either<Once<u32>, Once<u32>> = Either::Left(once(1));
assert_eq!(Some(1u32), either.next().await);
}
#[tokio::test]
async fn either_is_async_read() {
let mut buffer = [0; 3];
let mut either: Either<Repeat, Repeat> = Either::Right(repeat(0b101));
either.read_exact(&mut buffer).await.unwrap();
assert_eq!(buffer, [0b101, 0b101, 0b101]);
}
}

It should be ok to exclude these tests from loom, and then run all unit tests using loom.

working-directory: tokio-util
12 changes: 8 additions & 4 deletions tokio-stream/src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ cfg_sync! {
}

cfg_signal! {
#[cfg(unix)]
#[cfg(all(unix, not(loom)))]
mod signal_unix;
#[cfg(unix)]
#[cfg(all(unix, not(loom)))]
pub use signal_unix::SignalStream;

#[cfg(any(windows, docsrs))]
Expand All @@ -39,12 +39,14 @@ cfg_time! {
}

cfg_net! {
#[cfg(not(loom))]
mod tcp_listener;
#[cfg(not(loom))]
pub use tcp_listener::TcpListenerStream;

#[cfg(unix)]
#[cfg(all(unix, not(loom)))]
mod unix_listener;
#[cfg(unix)]
#[cfg(all(unix, not(loom)))]
pub use unix_listener::UnixListenerStream;
}

Expand All @@ -57,6 +59,8 @@ cfg_io_util! {
}

cfg_fs! {
#[cfg(not(loom))]
mod read_dir;
#[cfg(not(loom))]
pub use read_dir::ReadDirStream;
}
3 changes: 3 additions & 0 deletions tokio-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ futures-test = "0.3.5"
parking_lot = "0.12.0"
tempfile = "3.1.0"

[target.'cfg(loom)'.dev-dependencies]
loom = { version = "0.7", features = ["futures", "checkpoint"] }

[package.metadata.docs.rs]
all-features = true
# enable unstable features in the documentation
Expand Down
10 changes: 9 additions & 1 deletion tokio-util/src/loom.rs
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
pub(crate) use std::sync;
//! This module abstracts over `loom` and `std::sync` types depending on whether we
//! are running loom tests or not.

pub(crate) mod sync {
#[cfg(all(test, loom))]
pub(crate) use loom::sync::{Arc, Mutex, MutexGuard};
#[cfg(not(all(test, loom)))]
pub(crate) use std::sync::{Arc, Mutex, MutexGuard};
}
2 changes: 2 additions & 0 deletions tokio-util/src/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(loom))]

//! TCP/UDP/Unix helpers for tokio.

use crate::either::Either;
Expand Down
3 changes: 3 additions & 0 deletions tokio-util/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ pub use poll_semaphore::PollSemaphore;

mod reusable_box;
pub use reusable_box::ReusableBoxFuture;

#[cfg(test)]
mod tests;
3 changes: 2 additions & 1 deletion tokio-util/src/sync/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

#[cfg(loom)]
mod loom_cancellation_token;
2 changes: 2 additions & 0 deletions tokio-util/src/udp/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(loom))]

//! UDP framing

mod frame;
Expand Down
1 change: 1 addition & 0 deletions tokio-util/tests/udp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![warn(rust_2018_idioms)]
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support UDP
#![cfg(not(miri))] // No `socket` in Miri.
#![cfg(not(loom))] // No udp / UdpFramed in loom

use tokio::net::UdpSocket;
use tokio_stream::StreamExt;
Expand Down
Loading