Build tests for no-default-features into C/I

This commit is contained in:
John Nunley 2023-03-16 15:48:54 -07:00 committed by jtnunley
parent 1ec136a8a5
commit 2ac3be011e
3 changed files with 49 additions and 15 deletions

View File

@ -39,6 +39,7 @@ jobs:
run: cargo check -Z features=dev_dep
- run: cargo test --all
- run: cargo test --no-default-features --tests
- run: cargo build -p event-listener-strategy --no-default-features
- name: Install cargo-hack
uses: taiki-e/install-action@cargo-hack
- run: rustup target add thumbv7m-none-eabi
@ -56,6 +57,7 @@ jobs:
- name: Install Rust
run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
- run: cargo build --all
- run: cargo build --all --no-default-features
clippy:
runs-on: ubuntu-latest

View File

@ -80,6 +80,8 @@ use core::pin::Pin;
use core::ptr;
use core::task::{Context, Poll, Waker};
#[cfg(feature = "std")]
use parking::{Parker, Unparker};
#[cfg(feature = "std")]
use std::time::{Duration, Instant};
@ -661,7 +663,7 @@ impl<B: Borrow<Inner> + Unpin> Listener<B> {
std::thread_local! {
/// Cached thread-local parker/unparker pair.
static PARKER: RefCell<Option<(parking::Parker, Task)>> = RefCell::new(None);
static PARKER: RefCell<Option<(Parker, Task)>> = RefCell::new(None);
}
// Try to borrow the thread-local parker/unparker pair.
@ -693,7 +695,7 @@ impl<B: Borrow<Inner> + Unpin> Listener<B> {
fn wait_with_parker(
self: Pin<&mut Self>,
deadline: Option<Instant>,
parker: &parking::Parker,
parker: &Parker,
unparker: TaskRef<'_>,
) -> bool {
let (inner, mut listener) = self.project();
@ -818,7 +820,7 @@ enum Task {
/// An unparker that wakes up a thread.
#[cfg(feature = "std")]
Unparker(parking::Unparker),
Unparker(Unparker),
}
impl Task {
@ -855,7 +857,7 @@ enum TaskRef<'a> {
/// An unparker that wakes up a thread.
#[cfg(feature = "std")]
Unparker(&'a parking::Unparker),
Unparker(&'a Unparker),
}
impl TaskRef<'_> {

View File

@ -63,19 +63,24 @@ impl crate::Inner {
let entry = unsafe {
// SAFETY: We never move out the `link` field.
let listener = match listener.get_unchecked_mut() {
listener @ None => listener.insert(Listener {
link: UnsafeCell::new(Link {
state: Cell::new(State::Created),
prev: Cell::new(inner.tail),
next: Cell::new(None),
}),
_pin: PhantomPinned,
}),
listener @ None => {
// TODO: Use Option::insert once the MSRV is high enough.
*listener = Some(Listener {
link: UnsafeCell::new(Link {
state: Cell::new(State::Created),
prev: Cell::new(inner.tail),
next: Cell::new(None),
}),
_pin: PhantomPinned,
});
listener.as_mut().unwrap()
}
Some(_) => return,
};
// Get the inner pointer.
&mut *listener.link.get()
&*listener.link.get()
};
// Replace the tail with the new entry.
@ -123,7 +128,7 @@ impl crate::Inner {
let entry = unsafe {
// SAFETY: We never move out the `link` field.
let listener = listener.as_mut().get_unchecked_mut().as_mut()?;
&mut *listener.link.get()
&*listener.link.get()
};
// Take out the state and check it.
@ -183,7 +188,7 @@ impl Inner {
match next {
None => self.tail = prev,
Some(n) => unsafe {
n.as_ref().next.set(prev);
n.as_ref().prev.set(prev);
},
}
@ -340,5 +345,30 @@ mod tests {
// Remove one.
assert_eq!(inner.remove(listen2, false), Some(State::Created));
assert_eq!(inner.lock().len, 2);
// Remove another.
assert_eq!(inner.remove(listen1, false), Some(State::Created));
assert_eq!(inner.lock().len, 1);
}
#[test]
fn drop_non_notified() {
let inner = crate::Inner::new();
make_listeners!(listen1, listen2, listen3);
// Register the listeners.
inner.insert(listen1.as_mut());
inner.insert(listen2.as_mut());
inner.insert(listen3.as_mut());
// Notify one.
inner.notify(1, false);
// Remove one.
inner.remove(listen3, true);
// Remove the rest.
inner.remove(listen1, true);
inner.remove(listen2, true);
}
}