Skip to content

Commit

Permalink
tests: Add 1025 future test to executor
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Jul 21, 2024
1 parent f52b7ee commit 47100dd
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/sources/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ impl std::error::Error for ExecutorError {}
mod tests {
use super::*;

use std::cell::RefCell;
use std::rc::Rc;

#[test]
fn ready() {
let mut event_loop = crate::EventLoop::<u32>::try_new().unwrap();
Expand Down Expand Up @@ -439,4 +442,35 @@ mod tests {
// the future has run
assert_eq!(got, 42);
}

#[test]
fn more_than_1024() {
let mut event_loop = crate::EventLoop::<()>::try_new().unwrap();
let handle = event_loop.handle();

let (exec, sched) = executor::<()>().unwrap();
handle.insert_source(exec, move |_, _, _| ()).unwrap();

let counter = Rc::new(RefCell::new(0));
for _ in 0..1025 {
let counter = counter.clone();
sched
.schedule(async move {
*counter.borrow_mut() += 1;
})
.unwrap();
}

event_loop
.dispatch(Some(::std::time::Duration::ZERO), &mut ())
.unwrap();

assert_eq!(*counter.borrow(), 1024);

event_loop
.dispatch(Some(::std::time::Duration::ZERO), &mut ())
.unwrap();

assert_eq!(*counter.borrow(), 1025);
}
}

0 comments on commit 47100dd

Please sign in to comment.