From 39b9bf10244950223348357e90019751729904e2 Mon Sep 17 00:00:00 2001 From: Dom Dwyer Date: Wed, 31 Aug 2022 18:28:05 +0200 Subject: [PATCH] test: assert track_caller on permit merge --- tokio/tests/sync_panic.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tokio/tests/sync_panic.rs b/tokio/tests/sync_panic.rs index 11213b51544..6c23664998f 100644 --- a/tokio/tests/sync_panic.rs +++ b/tokio/tests/sync_panic.rs @@ -1,10 +1,10 @@ #![warn(rust_2018_idioms)] #![cfg(all(feature = "full", not(tokio_wasi)))] -use std::error::Error; +use std::{error::Error, sync::Arc}; use tokio::{ runtime::{Builder, Runtime}, - sync::{broadcast, mpsc, oneshot, Mutex, RwLock}, + sync::{broadcast, mpsc, oneshot, Mutex, RwLock, Semaphore}, }; mod support { @@ -160,6 +160,38 @@ fn mpsc_unbounded_receiver_blocking_recv_panic_caller() -> Result<(), Box Result<(), Box> { + let panic_location_file = test_panic(|| { + let sem1 = Arc::new(Semaphore::new(42)); + let sem2 = Arc::new(Semaphore::new(42)); + let mut p1 = sem1.try_acquire_owned().unwrap(); + let p2 = sem2.try_acquire_owned().unwrap(); + p1.merge(p2); + }); + + // The panic location should be in this file + assert_eq!(&panic_location_file.unwrap(), file!()); + + Ok(()) +} + +#[test] +fn semaphore_merge_unrelated_permits() -> Result<(), Box> { + let panic_location_file = test_panic(|| { + let sem1 = Semaphore::new(42); + let sem2 = Semaphore::new(42); + let mut p1 = sem1.try_acquire().unwrap(); + let p2 = sem2.try_acquire().unwrap(); + p1.merge(p2); + }); + + // The panic location should be in this file + assert_eq!(&panic_location_file.unwrap(), file!()); + + Ok(()) +} + fn current_thread() -> Runtime { Builder::new_current_thread().enable_all().build().unwrap() }