Skip to content

Commit

Permalink
Merge pull request #20 from goldwind-ting/main
Browse files Browse the repository at this point in the history
fix #18
  • Loading branch information
al8n authored May 21, 2022
2 parents d7849af + db8c0df commit 9298935
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cache/axync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ impl<'a, V, U, CB, S> CacheCleaner<'a, V, U, CB, S>
Some(item) = self.processor.insert_buf_rx.recv() => {
self.handle_item(item);
},
_ = async {} => return Ok(()),
else => return Ok(()),
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/cache/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,4 +1319,24 @@ mod async_test {
}
}
}

#[tokio::test]
async fn test_insert_after_clear() {
let ttl = Duration::from_secs(60);
let c: AsyncCache<u64, u64, TransparentKeyBuilder<u64>> = AsyncCache::builder(100, 10)
.set_key_builder(TransparentKeyBuilder::default())
.set_ignore_internal_cost(true)
.finalize()
.unwrap();

assert!(c.insert_with_ttl(0, 1, 1, ttl).await);
assert!(c.wait().await.is_ok());
assert_eq!(c.get(&0).unwrap().value(), &1);
assert!(c.clear().is_ok());
assert!(c.wait().await.is_ok());
assert!(c.get(&0).is_none());
assert!(c.insert_with_ttl(2, 3, 1, ttl).await);
assert!(c.wait().await.is_ok());
assert_eq!(c.get(&2).unwrap().value(), &3);
}
}

0 comments on commit 9298935

Please sign in to comment.