diff --git a/eth2/utils/hashmap_delay/Cargo.toml b/eth2/utils/hashmap_delay/Cargo.toml index da1536a3c4..e63ac46197 100644 --- a/eth2/utils/hashmap_delay/Cargo.toml +++ b/eth2/utils/hashmap_delay/Cargo.toml @@ -7,3 +7,6 @@ edition = "2018" [dependencies] futures = "0.3.4" tokio = { version = "0.2.19", features = ["time"] } + +[dev-dependencies] +tokio = { version = "0.2.19", features = ["time", "rt-threaded", "macros"] } diff --git a/eth2/utils/hashmap_delay/src/hashset_delay.rs b/eth2/utils/hashmap_delay/src/hashset_delay.rs index 756af9c86e..9ca45d1676 100644 --- a/eth2/utils/hashmap_delay/src/hashset_delay.rs +++ b/eth2/utils/hashmap_delay/src/hashset_delay.rs @@ -163,3 +163,30 @@ where } } } + +#[cfg(test)] + +mod tests { + use super::*; + + #[tokio::test] + async fn should_not_panic() { + let key = 2u8; + + let mut map = HashSetDelay::default(); + + map.insert(key); + map.update_timeout(&key, Duration::from_secs(100)); + + let fut = |cx: &mut Context| { + let _ = map.poll_next_unpin(cx); + let _ = map.poll_next_unpin(cx); + Poll::Ready(()) + }; + + future::poll_fn(fut).await; + + map.insert(key); + map.update_timeout(&key, Duration::from_secs(100)); + } +}