mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 13:28:49 +08:00
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)
|
||
|
}
|