Skip to content

Commit

Permalink
test: assert track_caller on permit merge
Browse files Browse the repository at this point in the history
  • Loading branch information
domodwyer committed Aug 31, 2022
1 parent ec172d4 commit 39b9bf1
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions 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 {
Expand Down Expand Up @@ -160,6 +160,38 @@ fn mpsc_unbounded_receiver_blocking_recv_panic_caller() -> Result<(), Box<dyn Er
Ok(())
}

#[test]
fn semaphore_merge_unrelated_owned_permits() -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
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()
}

0 comments on commit 39b9bf1

Please sign in to comment.