mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-03 04:19:18 +08:00
5b50731ff4
Signed-off-by: shaoyue.chen <shaoyue.chen@zilliz.com>
28 lines
562 B
Go
28 lines
562 B
Go
package proxy
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIDCache_SetGet(t *testing.T) {
|
|
cache := newIDCache(time.Hour, time.Hour)
|
|
// not exist before set
|
|
_, exist := cache.Get(1)
|
|
assert.False(t, exist)
|
|
cache.Set(1, true)
|
|
// exist after set & before expire
|
|
value, exist := cache.Get(1)
|
|
assert.True(t, exist)
|
|
assert.True(t, value)
|
|
|
|
cache = newIDCache(time.Millisecond, time.Hour)
|
|
cache.Set(1, true)
|
|
<-time.After(time.Millisecond)
|
|
// not exists after set & expire
|
|
_, exist = cache.Get(1)
|
|
assert.False(t, exist)
|
|
}
|