Skip to content

Commit d84a9e9

Browse files
benjaminranBenjamin Ran
andauthored
util: enable loom tests (#7644)
Co-authored-by: Benjamin Ran <[email protected]>
1 parent 0671c20 commit d84a9e9

File tree

12 files changed

+60
-7
lines changed

12 files changed

+60
-7
lines changed

.github/labeler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ R-loom-multi-thread:
1919
- tokio/src/runtime/scheduler/multi_thread/**
2020
- tokio/src/runtime/task/*
2121
- tokio/src/runtime/task/**
22+
23+
R-loom-util:
24+
- tokio-util/src/*
25+
- tokio-util/src/**/*

.github/workflows/loom.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,19 @@ jobs:
9595
working-directory: tokio
9696
env:
9797
SCOPE: ${{ matrix.scope }}
98+
99+
loom-util:
100+
name: loom tokio-util
101+
# base_ref is null when it's not a pull request
102+
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-util') || (github.base_ref == null))
103+
runs-on: ubuntu-latest
104+
steps:
105+
- uses: actions/checkout@v5
106+
- name: Install Rust ${{ env.rust_stable }}
107+
uses: dtolnay/rust-toolchain@master
108+
with:
109+
toolchain: ${{ env.rust_stable }}
110+
- uses: Swatinem/rust-cache@v2
111+
- name: run tests
112+
run: cargo test --lib --release --features full -- --nocapture
113+
working-directory: tokio-util

tokio-stream/src/wrappers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ cfg_sync! {
2222
}
2323

2424
cfg_signal! {
25-
#[cfg(unix)]
25+
#[cfg(all(unix, not(loom)))]
2626
mod signal_unix;
27-
#[cfg(unix)]
27+
#[cfg(all(unix, not(loom)))]
2828
pub use signal_unix::SignalStream;
2929

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

4141
cfg_net! {
42+
#[cfg(not(loom))]
4243
mod tcp_listener;
44+
#[cfg(not(loom))]
4345
pub use tcp_listener::TcpListenerStream;
4446

45-
#[cfg(unix)]
47+
#[cfg(all(unix, not(loom)))]
4648
mod unix_listener;
47-
#[cfg(unix)]
49+
#[cfg(all(unix, not(loom)))]
4850
pub use unix_listener::UnixListenerStream;
4951
}
5052

@@ -57,6 +59,8 @@ cfg_io_util! {
5759
}
5860

5961
cfg_fs! {
62+
#[cfg(not(loom))]
6063
mod read_dir;
64+
#[cfg(not(loom))]
6165
pub use read_dir::ReadDirStream;
6266
}

tokio-util/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ futures-test = "0.3.5"
5757
parking_lot = "0.12.0"
5858
tempfile = "3.1.0"
5959

60+
[target.'cfg(loom)'.dev-dependencies]
61+
loom = { version = "0.7", features = ["futures", "checkpoint"] }
62+
6063
[package.metadata.docs.rs]
6164
all-features = true
6265
# enable unstable features in the documentation

tokio-util/src/either.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ where
212212
}
213213
}
214214

215-
#[cfg(test)]
215+
#[cfg(all(test, not(loom)))]
216216
mod tests {
217217
use super::*;
218218
use tokio::io::{repeat, AsyncReadExt, Repeat};

tokio-util/src/loom.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
pub(crate) use std::sync;
1+
//! This module abstracts over `loom` and `std::sync` types depending on whether we
2+
//! are running loom tests or not.
3+
4+
pub(crate) mod sync {
5+
#[cfg(all(test, loom))]
6+
pub(crate) use loom::sync::{Arc, Mutex, MutexGuard};
7+
#[cfg(not(all(test, loom)))]
8+
pub(crate) use std::sync::{Arc, Mutex, MutexGuard};
9+
}

tokio-util/src/net/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(loom))]
2+
13
//! TCP/UDP/Unix helpers for tokio.
24
35
use crate::either::Either;

tokio-util/src/sync/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ pub use poll_semaphore::PollSemaphore;
1515

1616
mod reusable_box;
1717
pub use reusable_box::ReusableBoxFuture;
18+
19+
#[cfg(test)]
20+
mod tests;

tokio-util/src/sync/tests/loom_cancellation_token.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ fn drop_token_no_child() {
100100
});
101101
}
102102

103+
// Temporarily disabled due to a false positive in loom -
104+
// see https://github.com/tokio-rs/tokio/pull/7644#issuecomment-3328381344
105+
#[ignore]
103106
#[test]
104107
fn drop_token_with_children() {
105108
loom::model(|| {
@@ -125,6 +128,9 @@ fn drop_token_with_children() {
125128
});
126129
}
127130

131+
// Temporarily disabled due to a false positive in loom -
132+
// see https://github.com/tokio-rs/tokio/pull/7644#issuecomment-3328381344
133+
#[ignore]
128134
#[test]
129135
fn drop_and_cancel_token() {
130136
loom::model(|| {
@@ -150,6 +156,9 @@ fn drop_and_cancel_token() {
150156
});
151157
}
152158

159+
// Temporarily disabled due to a false positive in loom -
160+
// see https://github.com/tokio-rs/tokio/pull/7644#issuecomment-3328381344
161+
#[ignore]
153162
#[test]
154163
fn cancel_parent_and_child() {
155164
loom::model(|| {

tokio-util/src/sync/tests/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
1+
#[cfg(loom)]
2+
mod loom_cancellation_token;

0 commit comments

Comments
 (0)