summaryrefslogtreecommitdiffstats
path: root/tokio/tests
diff options
context:
space:
mode:
authorBlas Rodriguez Irizar <rodrigblas@gmail.com>2020-12-02 22:58:28 +0100
committerGitHub <noreply@github.com>2020-12-02 22:58:28 +0100
commita6051a61ec5c96113f4b543de3ec55431695347a (patch)
tree1a4d4bcc017f6a61a652505b1edd4a3bf36ea1ab /tokio/tests
parenta8e0f0a919663b210627c132d6af3e19a95d8037 (diff)
sync: make add_permits panic with usize::MAX >> 3 permits (#3188)
Diffstat (limited to 'tokio/tests')
-rw-r--r--tokio/tests/sync_semaphore.rs14
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);
+}