feat: don't GC task if expire time is 0 (#2102)
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
This commit is contained in:
parent
d7a7e69916
commit
fab5609d3d
|
|
@ -481,6 +481,12 @@ func (t *localTaskStore) CanReclaim() bool {
|
||||||
if t.invalid.Load() {
|
if t.invalid.Load() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// don't gc if expire time is 0
|
||||||
|
if t.expireTime == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
// task soft cache time reached
|
// task soft cache time reached
|
||||||
access := time.Unix(0, t.lastAccess.Load())
|
access := time.Unix(0, t.lastAccess.Load())
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
testifyassert "github.com/stretchr/testify/assert"
|
testifyassert "github.com/stretchr/testify/assert"
|
||||||
|
"go.uber.org/atomic"
|
||||||
|
|
||||||
commonv1 "d7y.io/api/pkg/apis/common/v1"
|
commonv1 "d7y.io/api/pkg/apis/common/v1"
|
||||||
|
|
||||||
|
|
@ -538,3 +539,46 @@ func TestLocalTaskStore_partialCompleted(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLocalTaskStore_CanReclaim(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
lts *localTaskStore
|
||||||
|
expect bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "normal task",
|
||||||
|
lts: &localTaskStore{},
|
||||||
|
expect: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "invalid task",
|
||||||
|
lts: &localTaskStore{
|
||||||
|
invalid: *atomic.NewBool(true),
|
||||||
|
},
|
||||||
|
expect: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "never expire task",
|
||||||
|
lts: &localTaskStore{
|
||||||
|
expireTime: 0,
|
||||||
|
},
|
||||||
|
expect: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "expired task",
|
||||||
|
lts: &localTaskStore{
|
||||||
|
expireTime: time.Second,
|
||||||
|
lastAccess: *atomic.NewInt64(1),
|
||||||
|
},
|
||||||
|
expect: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
assert := testifyassert.New(t)
|
||||||
|
assert.Equal(tc.lts.CanReclaim(), tc.expect)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue