mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
adjust TestCache_Expire_SetVar Test Code.
This commit is contained in:
@ -75,24 +75,25 @@ func TestCache_Set_Expire(t *testing.T) {
|
||||
|
||||
func TestCache_Expire_SetVar(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
gcache.Set(1, 11, 3*time.Second)
|
||||
expireBefore, okBefore := gcache.GetExpire(1)
|
||||
cache := gcache.New()
|
||||
cache.Set(1, 11, 3*time.Second)
|
||||
expireBefore, okBefore := cache.GetExpire(1)
|
||||
if okBefore {
|
||||
t.AssertGT(expireBefore, 0)
|
||||
}
|
||||
t.Assert(gcache.Get(1), 11)
|
||||
gcache.SetVar(1, 12)
|
||||
t.Assert(gcache.Get(1), 12)
|
||||
t.Assert(cache.Get(1), 11)
|
||||
cache.SetVar(1, 12)
|
||||
t.Assert(cache.Get(1), 12)
|
||||
time.Sleep(1 * time.Second)
|
||||
gcache.SetExpire(1, 5*time.Second)
|
||||
expireAfter, okAfter := gcache.GetExpire(1)
|
||||
cache.SetExpire(1, 5*time.Second)
|
||||
expireAfter, okAfter := cache.GetExpire(1)
|
||||
if okAfter {
|
||||
t.Assert(expireAfter-expireBefore, 3000)
|
||||
}
|
||||
time.Sleep(4 * time.Second)
|
||||
t.Assert(gcache.Get(1), 12)
|
||||
t.Assert(cache.Get(1), 12)
|
||||
time.Sleep(2 * time.Second)
|
||||
t.Assert(gcache.Get(1), nil)
|
||||
t.Assert(cache.Get(1), nil)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user