use super::assert_may_block;
use super::Section;
#[skuld::test]
fn outside_a_section_a_wait_is_allowed() {
assert_may_block("a test wait");
}
#[skuld::test]
#[should_panic(expected = "a test wait would block inside an async Drop")]
fn inside_a_section_a_wait_panics() {
let _section = Section::enter();
assert_may_block("a test wait");
}
#[skuld::test]
fn a_section_ends_when_dropped_and_nests() {
let outer = Section::enter();
let inner = Section::enter();
drop(inner);
assert!(
std::panic::catch_unwind(|| assert_may_block("outer")).is_err(),
"the outer section still covers this thread"
);
drop(outer);
assert_may_block("after both");
}
#[skuld::test]
fn a_section_is_per_thread() {
let _section = Section::enter();
std::thread::spawn(|| assert_may_block("another thread"))
.join()
.expect("a thread outside the section may block");
}
mod waits {
use super::Section;
#[skuld::test]
#[should_panic(expected = "would block inside an async Drop")]
fn block_until_exit_refuses_inside_a_section() {
let _section = Section::enter();
_ = crate::wait::block_until_exit(crate::identity::ProcessId::current(), Some(std::time::Duration::ZERO));
}
#[skuld::test]
#[should_panic(expected = "would block inside an async Drop")]
fn attached_wait_drained_refuses_inside_a_section() {
let _section = Section::enter();
_ = crate::containment::Attached::None.wait_drained(Some(Some(std::time::Instant::now())));
}
#[cfg(target_os = "linux")]
#[skuld::test(labels = [crate::test_harness::CGROUP])]
#[should_panic(expected = "would block inside an async Drop")]
fn cgroup_wait_drained_refuses_inside_a_section() {
use crate::containment::cgroup::test_support::{entered_leaf_at, FakeLeaf};
let fake = FakeLeaf::new("cosca-bounded-cgroup-wait-drained", true);
let leaf = entered_leaf_at(fake.leaf.clone());
leaf.disarm();
let _section = Section::enter();
_ = leaf.wait_drained(Some(Some(std::time::Instant::now())));
}
#[cfg(target_os = "macos")]
#[skuld::test]
#[should_panic(expected = "would block inside an async Drop")]
fn marker_wait_drained_refuses_inside_a_section() {
use crate::containment::fdmarker::{pipe_handle_of, Marker, PreparedMarker};
use std::os::fd::{AsFd, OwnedFd};
let (read, _write) = std::io::pipe().expect("pipe");
let read = OwnedFd::from(read);
let handle = pipe_handle_of(read.as_fd()).expect("handle");
let marker = Marker::new(
PreparedMarker {
read,
handle,
read_handle: handle,
fd: 3,
},
crate::containment::fdmarker::fdmarker_tests::inert_root(),
None,
);
let _section = Section::enter();
_ = marker.wait_drained(Some(Some(std::time::Instant::now())));
}
#[cfg(windows)]
#[skuld::test]
#[should_panic(expected = "would block inside an async Drop")]
fn job_wait_drained_refuses_inside_a_section() {
let job = crate::containment::windows::JobHandle::create_empty_for_test();
let _section = Section::enter();
_ = job.wait_drained(Some(Some(std::time::Instant::now())), None);
}
#[cfg(windows)]
#[skuld::test]
#[should_panic(expected = "would block inside an async Drop")]
fn job_wait_drained_raw_refuses_inside_a_section() {
let job = crate::containment::windows::JobHandle::create_empty_for_test();
let raw = job.as_handle().expect("a live job handle");
let _section = Section::enter();
_ = crate::containment::windows::wait_drained_raw(raw, Some(Some(std::time::Instant::now())), None);
}
#[cfg(windows)]
#[skuld::test]
#[should_panic(expected = "would block inside an async Drop")]
fn block_until_exit_or_cancel_refuses_inside_a_section() {
let cancel = crate::wait::backend::new_cancel_event().expect("event");
let _section = Section::enter();
_ = crate::wait::backend::block_until_exit_or_cancel(
crate::identity::ProcessId::current(),
Some(std::time::Instant::now()),
&cancel,
);
}
}