Skip to content

Commit

Permalink
test engine cache expire
Browse files Browse the repository at this point in the history
  • Loading branch information
zc authored and CMGS committed Jul 24, 2019
1 parent 0d2a714 commit 285bec3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion utils/cache.go
Expand Up @@ -13,7 +13,7 @@ type EngineCache struct {
cache *cache.Cache
}

// NewCache creates Cache instance
// NewCacheCache creates Cache instance
func NewEngineCache(expire time.Duration, cleanupInterval time.Duration) *EngineCache {
return &EngineCache{
cache: cache.New(expire, cleanupInterval),
Expand Down
4 changes: 3 additions & 1 deletion utils/cache_test.go
Expand Up @@ -9,12 +9,14 @@ import (
)

func TestCache(t *testing.T) {
c := NewEngineCache(time.Hour, time.Minute)
c := NewEngineCache(2*time.Second, time.Second)

host := "1.1.1.1"
cli := &enginemocks.API{}
c.Set(host, cli)
assert.Equal(t, c.Get(host), cli)
c.Delete(host)
assert.Nil(t, c.Get(host))
time.Sleep(3 * time.Second)
assert.Nil(t, c.Get(host))
}

0 comments on commit 285bec3

Please sign in to comment.