adjust TestCache_Expire_SetVar Test Code.

This commit is contained in:
糖水不加糖
2020-08-07 14:05:21 +08:00
parent 8a84ca16d1
commit 919eaf1e9a

View File

@ -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)
})
}