From 822af18cf5fde60b134943067647ee35405c3797 Mon Sep 17 00:00:00 2001 From: Alice Ryhl Date: Sat, 25 Mar 2023 19:09:05 +0100 Subject: [PATCH] sync: fix `Semaphore::MAX_PERMITS` test (#5582) --- tokio/src/sync/tests/semaphore_batch.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tokio/src/sync/tests/semaphore_batch.rs b/tokio/src/sync/tests/semaphore_batch.rs index c9e9d05ec8f..85089cd2213 100644 --- a/tokio/src/sync/tests/semaphore_batch.rs +++ b/tokio/src/sync/tests/semaphore_batch.rs @@ -1,6 +1,8 @@ use crate::sync::batch_semaphore::Semaphore; use tokio_test::*; +const MAX_PERMITS: usize = crate::sync::Semaphore::MAX_PERMITS; + #[cfg(tokio_wasm_not_wasi)] use wasm_bindgen_test::wasm_bindgen_test as test; @@ -168,12 +170,16 @@ fn poll_acquire_one_zero_permits() { assert_ready_ok!(acquire.poll()); } +#[test] +fn max_permits_doesnt_panic() { + Semaphore::new(MAX_PERMITS); +} + #[test] #[should_panic] #[cfg(not(tokio_wasm))] // wasm currently doesn't support unwinding fn validates_max_permits() { - use std::usize; - Semaphore::new((usize::MAX >> 2) + 1); + Semaphore::new(MAX_PERMITS + 1); } #[test]