2019-07-11 06:51:55 +02:00
|
|
|
package memory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2019-10-03 10:46:20 +02:00
|
|
|
"github.com/micro/go-micro/store"
|
2019-07-11 06:51:55 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2019-07-11 06:51:55 +02:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|