diff options
author | Blas Rodriguez Irizar <rodrigblas@gmail.com> | 2020-12-02 22:58:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-02 22:58:28 +0100 |
commit | a6051a61ec5c96113f4b543de3ec55431695347a (patch) | |
tree | 1a4d4bcc017f6a61a652505b1edd4a3bf36ea1ab /tokio/tests/sync_semaphore.rs | |
parent | a8e0f0a919663b210627c132d6af3e19a95d8037 (diff) |
sync: make add_permits panic with usize::MAX >> 3 permits (#3188)
Diffstat (limited to 'tokio/tests/sync_semaphore.rs')
-rw-r--r-- | tokio/tests/sync_semaphore.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tokio/tests/sync_semaphore.rs b/tokio/tests/sync_semaphore.rs index 1cb0c749..a33b878b 100644 --- a/tokio/tests/sync_semaphore.rs +++ b/tokio/tests/sync_semaphore.rs @@ -79,3 +79,17 @@ async fn stresstest() { let _p5 = sem.try_acquire().unwrap(); assert!(sem.try_acquire().is_err()); } + +#[test] +fn add_max_amount_permits() { + let s = tokio::sync::Semaphore::new(0); + s.add_permits(usize::MAX >> 3); + assert_eq!(s.available_permits(), usize::MAX >> 3); +} + +#[test] +#[should_panic] +fn add_more_than_max_amount_permits() { + let s = tokio::sync::Semaphore::new(1); + s.add_permits(usize::MAX >> 3); +} |