1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00
go-micro/store/memory/memory_test.go

38 lines
573 B
Go
Raw Normal View History

package memory
import (
"testing"
"time"
"github.com/micro/go-micro/store"
)
func TestReadRecordExpire(t *testing.T) {
s := NewStore()
var (
key = "foo"
expire = 100 * time.Millisecond
)
rec := &store.Record{
Key: key,
Value: nil,
Expiry: expire,
}
s.Write(rec)
rrec, err := s.Read(key)
if err != nil {
t.Fatal(err)
}
2019-10-11 15:08:50 +02:00
if rrec[0].Expiry >= expire {
t.Fatal("expiry of read record is not changed")
}
time.Sleep(expire)
if _, err := s.Read(key); err != store.ErrNotFound {
t.Fatal("expire elapsed, but key still accessable")
}
}