Ocache fix tests and return deadline back

This commit is contained in:
mcrakhman committed 2022-10-21 11:21:20 +02:00
1 parent 27b3213bac
commit 40ce73db68
2 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -356,6 +356,7 @@ func (c *oCache) GC() {
c.mu.Unlock()
return
}
deadline := c.timeNow().Add(-c.ttl)
var toClose []*entry
for _, e := range c.data {
if e.isClosing {
@@ -365,8 +366,7 @@ func (c *oCache) GC() {
if lug, ok := e.value.(ObjectLastUsage); ok {
lu = lug.LastUsage()
}
deadline := lu.Add(c.ttl)
if !e.locked() && e.refCount <= 0 && c.timeNow().After(deadline) {
if !e.locked() && e.refCount <= 0 && lu.Before(deadline) {
e.isClosing = true
e.close = make(chan struct{})
toClose = append(toClose, e)
+2 -2
View File
@@ -119,7 +119,7 @@ func TestOCache_GC(t *testing.T) {
t.Run("test without close wait", func(t *testing.T) {
c := New(func(ctx context.Context, id string) (value Object, err error) {
return &testObject{name: id}, nil
}, WithTTL(time.Millisecond*10))
}, WithTTL(time.Millisecond*10), WithRefCounter(true))
val, err := c.Get(context.TODO(), "id")
require.NoError(t, err)
require.NotNil(t, val)
@@ -140,7 +140,7 @@ func TestOCache_GC(t *testing.T) {
c := New(func(ctx context.Context, id string) (value Object, err error) {
return NewTestObject(id, closeCh), nil
}, WithTTL(time.Millisecond*10))
}, WithTTL(time.Millisecond*10), WithRefCounter(true))
val, err := c.Get(context.TODO(), "id")
require.NoError(t, err)
require.NotNil(t, val)