mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-01-11 21:44:24 +00:00
ac4e060e1a
* adding raises defect across the codebase * use unittest2 * add windows deps caching * update mingw link * die on failed peerinfo initialization * use result.expect instead of get * use expect more consistently and rework inits * use expect more consistently * throw on missing public key * remove unused closure annotation * merge master
39 lines
737 B
Nim
39 lines
737 B
Nim
{.used.}
|
|
|
|
import unittest2
|
|
import chronos/timer
|
|
import ../../libp2p/protocols/pubsub/timedcache
|
|
|
|
suite "TimedCache":
|
|
test "put/get":
|
|
var cache = TimedCache[int].init(5.seconds)
|
|
|
|
let now = Moment.now()
|
|
check:
|
|
not cache.put(1, now)
|
|
not cache.put(2, now + 3.seconds)
|
|
|
|
check:
|
|
1 in cache
|
|
2 in cache
|
|
|
|
check: not cache.put(3, now + 6.seconds) # expires 1
|
|
|
|
check:
|
|
1 notin cache
|
|
2 in cache
|
|
3 in cache
|
|
|
|
check:
|
|
cache.put(2, now + 7.seconds) # refreshes 2
|
|
not cache.put(4, now + 12.seconds) # expires 3
|
|
|
|
check:
|
|
2 in cache
|
|
3 notin cache
|
|
4 in cache
|
|
|
|
check:
|
|
not cache.put(100, now + 100.seconds) # expires everything
|
|
100 in cache
|