Skip to content

Commit 95428ec

Browse files
committed
Try activating loom tests
1 parent 963d922 commit 95428ec

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

.github/workflows/loom.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
on:
22
push:
3-
branches: ["master", "tokio-*.x"]
3+
branches: ["*"]
44
pull_request:
55
types: [labeled, opened, synchronize, reopened]
66
branches: ["master", "tokio-*.x"]
@@ -26,7 +26,7 @@ jobs:
2626
loom-sync:
2727
name: loom tokio::sync
2828
# base_ref is null when it's not a pull request
29-
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-sync') || (github.base_ref == null))
29+
# if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-sync') || (github.base_ref == null))
3030
runs-on: ubuntu-latest
3131
steps:
3232
- uses: actions/checkout@v4
@@ -42,7 +42,7 @@ jobs:
4242
loom-time-driver:
4343
name: loom time driver
4444
# base_ref is null when it's not a pull request
45-
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-time-driver') || (github.base_ref == null))
45+
# if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-time-driver') || (github.base_ref == null))
4646
runs-on: ubuntu-latest
4747
steps:
4848
- uses: actions/checkout@v4
@@ -58,7 +58,7 @@ jobs:
5858
loom-current-thread:
5959
name: loom current-thread scheduler
6060
# base_ref is null when it's not a pull request
61-
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-current-thread') || (github.base_ref == null))
61+
# if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-current-thread') || (github.base_ref == null))
6262
runs-on: ubuntu-latest
6363
steps:
6464
- uses: actions/checkout@v4
@@ -74,7 +74,7 @@ jobs:
7474
loom-multi-thread:
7575
name: loom multi-thread scheduler
7676
# base_ref is null when it's not a pull request
77-
if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-multi-thread') || (github.base_ref == null))
77+
# if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-multi-thread') || (github.base_ref == null))
7878
runs-on: ubuntu-latest
7979
strategy:
8080
matrix:
@@ -99,7 +99,7 @@ jobs:
9999
loom-multi-thread-alt:
100100
name: loom ALT multi-thread scheduler
101101
# 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-multi-thread-alt') || (github.base_ref == null))
102+
# if: github.repository_owner == 'tokio-rs' && (contains(github.event.pull_request.labels.*.name, 'R-loom-multi-thread-alt') || (github.base_ref == null))
103103
runs-on: ubuntu-latest
104104
strategy:
105105
matrix:

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

+46
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,49 @@ fn cancel_parent_and_child() {
174174
assert_ok!(th3.join());
175175
});
176176
}
177+
178+
#[test]
179+
fn run_until_cancelled_completes() {
180+
loom::model(|| {
181+
block_on(async {
182+
let token = CancellationToken::new();
183+
184+
let fut = async {
185+
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
186+
42
187+
};
188+
189+
if let Some(res) = token.run_until_cancelled(fut).await {
190+
assert!(res, 42);
191+
} else {
192+
// Should not happen since we are not cancelling the token
193+
assert!(false);
194+
}
195+
});
196+
});
197+
}
198+
199+
#[test]
200+
fn run_until_cancelled_with_cancel() {
201+
loom::model(|| {
202+
block_on(async {
203+
let token = CancellationToken::new();
204+
let token1 = token.clone();
205+
206+
let th1 = std::thread::spawn(move || {
207+
std::time::sleep(std::time::Duration::from_millis(500));
208+
token1.cancel();
209+
});
210+
211+
if let None = token.run_until_cancelled(std::future::pending).await {
212+
assert!(true);
213+
} else {
214+
// This branch should not be entered since we cancel the token before the future
215+
// finishes
216+
assert!(false);
217+
}
218+
219+
assert_ok!(th1.join());
220+
});
221+
});
222+
}

0 commit comments

Comments
 (0)