mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
f23638c036
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
38 lines
576 B
Go
38 lines
576 B
Go
package memory
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/micro/go-micro/v2/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)
|
|
}
|
|
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")
|
|
}
|
|
}
|