tests: fix ol' forker dumping core in tests
This commit is contained in:
parent
3bd1813d50
commit
22b7fb2ced
5 changed files with 34 additions and 6 deletions
|
|
@ -7,7 +7,13 @@ use {
|
||||||
async_engine::ae_task::Runnable,
|
async_engine::ae_task::Runnable,
|
||||||
utils::{array, numcell::NumCell, syncqueue::SyncQueue},
|
utils::{array, numcell::NumCell, syncqueue::SyncQueue},
|
||||||
},
|
},
|
||||||
std::{cell::RefCell, collections::VecDeque, future::Future, rc::Rc, task::Waker},
|
std::{
|
||||||
|
cell::{Cell, RefCell},
|
||||||
|
collections::VecDeque,
|
||||||
|
future::Future,
|
||||||
|
rc::Rc,
|
||||||
|
task::Waker,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
|
|
@ -26,6 +32,7 @@ pub struct AsyncEngine {
|
||||||
yields: SyncQueue<Waker>,
|
yields: SyncQueue<Waker>,
|
||||||
stash: RefCell<VecDeque<Runnable>>,
|
stash: RefCell<VecDeque<Runnable>>,
|
||||||
yield_stash: RefCell<VecDeque<Waker>>,
|
yield_stash: RefCell<VecDeque<Waker>>,
|
||||||
|
stopped: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncEngine {
|
impl AsyncEngine {
|
||||||
|
|
@ -37,9 +44,14 @@ impl AsyncEngine {
|
||||||
yields: Default::default(),
|
yields: Default::default(),
|
||||||
stash: Default::default(),
|
stash: Default::default(),
|
||||||
yield_stash: Default::default(),
|
yield_stash: Default::default(),
|
||||||
|
stopped: Cell::new(false),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn stop(&self) {
|
||||||
|
self.stopped.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn clear(&self) {
|
pub fn clear(&self) {
|
||||||
self.stash.borrow_mut().clear();
|
self.stash.borrow_mut().clear();
|
||||||
self.yield_stash.borrow_mut().clear();
|
self.yield_stash.borrow_mut().clear();
|
||||||
|
|
@ -83,6 +95,9 @@ impl AsyncEngine {
|
||||||
self.num_queued.fetch_sub(stash.len());
|
self.num_queued.fetch_sub(stash.len());
|
||||||
for runnable in stash.drain(..) {
|
for runnable in stash.drain(..) {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
|
if self.stopped.get() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.yields.swap(&mut *yield_stash);
|
self.yields.swap(&mut *yield_stash);
|
||||||
|
|
|
||||||
|
|
@ -338,7 +338,7 @@ impl Forker {
|
||||||
let _f1 = ae.spawn(forker.clone().incoming());
|
let _f1 = ae.spawn(forker.clone().incoming());
|
||||||
let _f2 = ae.spawn(forker.clone().outgoing());
|
let _f2 = ae.spawn(forker.clone().outgoing());
|
||||||
let _ = ring.run();
|
let _ = ring.run();
|
||||||
unreachable!();
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn outgoing(self: Rc<Self>) {
|
async fn outgoing(self: Rc<Self>) {
|
||||||
|
|
@ -348,14 +348,23 @@ impl Forker {
|
||||||
for fd in self.fds.borrow_mut().drain(..) {
|
for fd in self.fds.borrow_mut().drain(..) {
|
||||||
io.push_fd(fd);
|
io.push_fd(fd);
|
||||||
}
|
}
|
||||||
io.write_msg(msg).await.unwrap();
|
if io.write_msg(msg).await.is_err() {
|
||||||
|
self.ring.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn incoming(self: Rc<Self>) {
|
async fn incoming(self: Rc<Self>) {
|
||||||
let mut io = IoIn::new(&self.socket, &self.ring);
|
let mut io = IoIn::new(&self.socket, &self.ring);
|
||||||
loop {
|
loop {
|
||||||
let msg = io.read_msg().await.unwrap();
|
let msg = match io.read_msg().await {
|
||||||
|
Ok(m) => m,
|
||||||
|
_ => {
|
||||||
|
self.ring.stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
self.handle_msg(msg, &mut io);
|
self.handle_msg(msg, &mut io);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -409,6 +409,7 @@ impl IoUringData {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn kill(&self) {
|
fn kill(&self) {
|
||||||
|
self.eng.stop();
|
||||||
let mut to_cancel = vec![];
|
let mut to_cancel = vec![];
|
||||||
for task in self.tasks.lock().values() {
|
for task in self.tasks.lock().values() {
|
||||||
if !task.is_cancel() {
|
if !task.is_cancel() {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use {
|
||||||
utils::errorfmt::ErrorFmt,
|
utils::errorfmt::ErrorFmt,
|
||||||
},
|
},
|
||||||
std::cell::Cell,
|
std::cell::Cell,
|
||||||
|
uapi::c,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct AsyncCancelTask {
|
pub struct AsyncCancelTask {
|
||||||
|
|
@ -36,7 +37,9 @@ unsafe impl Task for AsyncCancelTask {
|
||||||
|
|
||||||
fn complete(self: Box<Self>, ring: &IoUringData, res: i32) {
|
fn complete(self: Box<Self>, ring: &IoUringData, res: i32) {
|
||||||
if let Err(e) = map_err!(res) {
|
if let Err(e) = map_err!(res) {
|
||||||
log::debug!("Could not cancel task: {}", ErrorFmt(e));
|
if e.0 != c::ENOENT {
|
||||||
|
log::debug!("Could not cancel task: {}", ErrorFmt(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ring.cached_cancels.push(self);
|
ring.cached_cancels.push(self);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ fn run_test(it_run: &ItRun, test: &'static dyn TestCase, cfg: Rc<TestConfig>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
errors.set(testrun.errors.take());
|
errors.set(testrun.errors.take());
|
||||||
state.el.stop();
|
state.ring.stop();
|
||||||
pending().await
|
pending().await
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue