Skip to content

Commit 58edfc6

Browse files
authored
ci: verify that tests work with panic=abort (#6283)
1 parent bfd7b08 commit 58edfc6

File tree

17 files changed

+49
-46
lines changed

17 files changed

+49
-46
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,34 @@ jobs:
148148
cargo nextest run --workspace --all-features
149149
cargo test --doc --workspace --all-features
150150
151+
test-workspace-all-features-panic-abort:
152+
needs: basics
153+
name: test all crates in the workspace with all features and panic=abort
154+
runs-on: ${{ matrix.os }}
155+
strategy:
156+
matrix:
157+
os:
158+
- windows-latest
159+
- ubuntu-latest
160+
- macos-latest
161+
steps:
162+
- uses: actions/checkout@v4
163+
- name: Install Rust ${{ env.rust_nightly }}
164+
uses: dtolnay/rust-toolchain@stable
165+
with:
166+
toolchain: ${{ env.rust_nightly }}
167+
- name: Install cargo-nextest
168+
uses: taiki-e/install-action@v2
169+
with:
170+
tool: cargo-nextest
171+
172+
- uses: Swatinem/rust-cache@v2
173+
174+
- name: test all --all-features panic=abort
175+
run: |
176+
set -euxo pipefail
177+
RUSTFLAGS="$RUSTFLAGS -C panic=abort -Zpanic-abort-tests" cargo nextest run --workspace --exclude tokio-macros --exclude tests-build --all-features --tests
178+
151179
test-integration-tests-per-feature:
152180
needs: basics
153181
name: Run integration tests for each feature

tokio-stream/tests/stream_panic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms)]
22
#![cfg(all(feature = "time", not(target_os = "wasi")))] // Wasi does not support panic recovery
3+
#![cfg(panic = "unwind")]
34

45
use parking_lot::{const_mutex, Mutex};
56
use std::error::Error;

tokio-util/tests/panic.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms)]
22
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
3+
#![cfg(panic = "unwind")]
34

45
use parking_lot::{const_mutex, Mutex};
56
use std::error::Error;
@@ -76,7 +77,6 @@ fn poll_sender_send_item_panic_caller() -> Result<(), Box<dyn Error>> {
7677
}
7778

7879
#[test]
79-
8080
fn local_pool_handle_new_panic_caller() -> Result<(), Box<dyn Error>> {
8181
let panic_location_file = test_panic(|| {
8282
let _ = LocalPoolHandle::new(0);
@@ -89,7 +89,6 @@ fn local_pool_handle_new_panic_caller() -> Result<(), Box<dyn Error>> {
8989
}
9090

9191
#[test]
92-
9392
fn local_pool_handle_spawn_pinned_by_idx_panic_caller() -> Result<(), Box<dyn Error>> {
9493
let panic_location_file = test_panic(|| {
9594
let rt = basic();

tokio-util/tests/spawn_pinned.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ async fn can_spawn_multiple_futures() {
7171
/// A panic in the spawned task causes the join handle to return an error.
7272
/// But, you can continue to spawn tasks.
7373
#[tokio::test]
74+
#[cfg(panic = "unwind")]
7475
async fn task_panic_propagates() {
7576
let pool = task::LocalPoolHandle::new(1);
7677

@@ -95,6 +96,7 @@ async fn task_panic_propagates() {
9596
/// A panic during task creation causes the join handle to return an error.
9697
/// But, you can continue to spawn tasks.
9798
#[tokio::test]
99+
#[cfg(panic = "unwind")]
98100
async fn callback_panic_does_not_kill_worker() {
99101
let pool = task::LocalPoolHandle::new(1);
100102

tokio-util/tests/time_delay_queue.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ async fn item_expiry_greater_than_wheel() {
805805

806806
#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")]
807807
#[tokio::test(start_paused = true)]
808+
#[cfg(panic = "unwind")]
808809
async fn remove_after_compact() {
809810
let now = Instant::now();
810811
let mut queue = DelayQueue::new();
@@ -822,6 +823,7 @@ async fn remove_after_compact() {
822823

823824
#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")]
824825
#[tokio::test(start_paused = true)]
826+
#[cfg(panic = "unwind")]
825827
async fn remove_after_compact_poll() {
826828
let now = Instant::now();
827829
let mut queue = task::spawn(DelayQueue::new());

tokio/src/runtime/tests/task_combinations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ enum CombiAbortSource {
6464
AbortHandle,
6565
}
6666

67-
#[cfg(panic = "unwind")]
6867
#[test]
68+
#[cfg_attr(panic = "abort", ignore)]
6969
fn test_combinations() {
7070
let mut rt = &[
7171
CombiRuntime::CurrentThread,

tokio/tests/io_panic.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms)]
22
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery
3+
#![cfg(panic = "unwind")]
34

45
use std::task::{Context, Poll};
56
use std::{error::Error, pin::Pin};
@@ -54,7 +55,6 @@ mod unix {
5455
}
5556
}
5657

57-
#[cfg(panic = "unwind")]
5858
#[test]
5959
fn read_buf_initialize_unfilled_to_panic_caller() -> Result<(), Box<dyn Error>> {
6060
let panic_location_file = test_panic(|| {
@@ -70,7 +70,6 @@ fn read_buf_initialize_unfilled_to_panic_caller() -> Result<(), Box<dyn Error>>
7070
Ok(())
7171
}
7272

73-
#[cfg(panic = "unwind")]
7473
#[test]
7574
fn read_buf_advance_panic_caller() -> Result<(), Box<dyn Error>> {
7675
let panic_location_file = test_panic(|| {
@@ -86,7 +85,6 @@ fn read_buf_advance_panic_caller() -> Result<(), Box<dyn Error>> {
8685
Ok(())
8786
}
8887

89-
#[cfg(panic = "unwind")]
9088
#[test]
9189
fn read_buf_set_filled_panic_caller() -> Result<(), Box<dyn Error>> {
9290
let panic_location_file = test_panic(|| {
@@ -102,7 +100,6 @@ fn read_buf_set_filled_panic_caller() -> Result<(), Box<dyn Error>> {
102100
Ok(())
103101
}
104102

105-
#[cfg(panic = "unwind")]
106103
#[test]
107104
fn read_buf_put_slice_panic_caller() -> Result<(), Box<dyn Error>> {
108105
let panic_location_file = test_panic(|| {
@@ -120,7 +117,6 @@ fn read_buf_put_slice_panic_caller() -> Result<(), Box<dyn Error>> {
120117
Ok(())
121118
}
122119

123-
#[cfg(panic = "unwind")]
124120
#[test]
125121
fn unsplit_panic_caller() -> Result<(), Box<dyn Error>> {
126122
let panic_location_file = test_panic(|| {

tokio/tests/join_handle_panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms)]
22
#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery
3+
#![cfg(panic = "unwind")]
34

45
struct PanicsOnDrop;
56

@@ -9,7 +10,6 @@ impl Drop for PanicsOnDrop {
910
}
1011
}
1112

12-
#[cfg(panic = "unwind")]
1313
#[tokio::test]
1414
async fn test_panics_do_not_propagate_when_dropping_join_handle() {
1515
let join_handle = tokio::spawn(async move { PanicsOnDrop });

tokio/tests/net_panic.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(rust_2018_idioms)]
22
#![cfg(all(feature = "full", not(target_os = "wasi")))]
3+
#![cfg(panic = "unwind")]
34

45
use std::error::Error;
56
use tokio::net::{TcpListener, TcpStream};
@@ -10,7 +11,6 @@ mod support {
1011
}
1112
use support::panic::test_panic;
1213

13-
#[cfg(panic = "unwind")]
1414
#[test]
1515
fn udp_socket_from_std_panic_caller() -> Result<(), Box<dyn Error>> {
1616
use std::net::SocketAddr;
@@ -33,7 +33,6 @@ fn udp_socket_from_std_panic_caller() -> Result<(), Box<dyn Error>> {
3333
Ok(())
3434
}
3535

36-
#[cfg(panic = "unwind")]
3736
#[test]
3837
fn tcp_listener_from_std_panic_caller() -> Result<(), Box<dyn Error>> {
3938
let std_listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
@@ -52,7 +51,6 @@ fn tcp_listener_from_std_panic_caller() -> Result<(), Box<dyn Error>> {
5251
Ok(())
5352
}
5453

55-
#[cfg(panic = "unwind")]
5654
#[test]
5755
fn tcp_stream_from_std_panic_caller() -> Result<(), Box<dyn Error>> {
5856
let std_listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
@@ -166,7 +164,6 @@ fn unix_datagram_from_std_panic_caller() -> Result<(), Box<dyn Error>> {
166164
Ok(())
167165
}
168166

169-
#[cfg(panic = "unwind")]
170167
#[test]
171168
#[cfg(windows)]
172169
fn server_options_max_instances_panic_caller() -> Result<(), Box<dyn Error>> {

tokio/tests/process_issue_2174.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use tokio::time;
1717
use tokio_test::assert_err;
1818

1919
#[tokio::test]
20+
#[cfg_attr(panic = "abort", ignore)]
2021
async fn issue_2174() {
2122
let mut child = Command::new("sleep")
2223
.arg("2")

tokio/tests/rt_handle.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use tokio::runtime::Runtime;
55

6-
#[cfg(panic = "unwind")]
76
#[test]
7+
#[cfg_attr(panic = "abort", ignore)]
88
fn basic_enter() {
99
let rt1 = rt();
1010
let rt2 = rt();
@@ -16,9 +16,9 @@ fn basic_enter() {
1616
drop(enter1);
1717
}
1818

19-
#[cfg(panic = "unwind")]
2019
#[test]
2120
#[should_panic]
21+
#[cfg_attr(panic = "abort", ignore)]
2222
fn interleave_enter_different_rt() {
2323
let rt1 = rt();
2424
let rt2 = rt();
@@ -30,9 +30,9 @@ fn interleave_enter_different_rt() {
3030
drop(enter2);
3131
}
3232

33-
#[cfg(panic = "unwind")]
3433
#[test]
3534
#[should_panic]
35+
#[cfg_attr(panic = "abort", ignore)]
3636
fn interleave_enter_same_rt() {
3737
let rt1 = rt();
3838

@@ -44,9 +44,9 @@ fn interleave_enter_same_rt() {
4444
drop(enter3);
4545
}
4646

47-
#[cfg(panic = "unwind")]
4847
#[test]
4948
#[cfg(not(target_os = "wasi"))]
49+
#[cfg_attr(panic = "abort", ignore)]
5050
fn interleave_then_enter() {
5151
let _ = std::panic::catch_unwind(|| {
5252
let rt1 = rt();

tokio/tests/rt_panic.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![warn(rust_2018_idioms)]
22
#![cfg(feature = "full")]
33
#![cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery
4+
#![cfg(panic = "unwind")]
45

56
use futures::future;
67
use std::error::Error;
@@ -11,7 +12,6 @@ mod support {
1112
}
1213
use support::panic::test_panic;
1314

14-
#[cfg(panic = "unwind")]
1515
#[test]
1616
fn current_handle_panic_caller() -> Result<(), Box<dyn Error>> {
1717
let panic_location_file = test_panic(|| {
@@ -24,7 +24,6 @@ fn current_handle_panic_caller() -> Result<(), Box<dyn Error>> {
2424
Ok(())
2525
}
2626

27-
#[cfg(panic = "unwind")]
2827
#[test]
2928
fn into_panic_panic_caller() -> Result<(), Box<dyn Error>> {
3029
let panic_location_file = test_panic(move || {
@@ -47,7 +46,6 @@ fn into_panic_panic_caller() -> Result<(), Box<dyn Error>> {
4746
Ok(())
4847
}
4948

50-
#[cfg(panic = "unwind")]
5149
#[test]
5250
fn builder_worker_threads_panic_caller() -> Result<(), Box<dyn Error>> {
5351
let panic_location_file = test_panic(|| {
@@ -60,7 +58,6 @@ fn builder_worker_threads_panic_caller() -> Result<(), Box<dyn Error>> {
6058
Ok(())
6159
}
6260

63-
#[cfg(panic = "unwind")]
6461
#[test]
6562
fn builder_max_blocking_threads_panic_caller() -> Result<(), Box<dyn Error>> {
6663
let panic_location_file = test_panic(|| {

tokio/tests/signal_panic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![warn(rust_2018_idioms)]
22
#![cfg(feature = "full")]
33
#![cfg(unix)]
4+
#![cfg(panic = "unwind")]
45

56
use std::error::Error;
67
use tokio::runtime::Builder;

0 commit comments

Comments
 (0)