Skip to content

Commit 8c6d707

Browse files
authored
fix(cache): cache test triggered by non memory cache (#33220)
Change SlowCacheThreshold to 30 milliseconds so it doesn't trigger on non memory cache Closes: #33190 Closes: #32657
1 parent 5c150ce commit 8c6d707

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

modules/cache/cache.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ func Init() error {
3737
}
3838

3939
const (
40-
testCacheKey = "DefaultCache.TestKey"
41-
SlowCacheThreshold = 100 * time.Microsecond
40+
testCacheKey = "DefaultCache.TestKey"
41+
// SlowCacheThreshold marks cache tests as slow
42+
// set to 30ms per discussion: https://github.com/go-gitea/gitea/issues/33190
43+
// TODO: Replace with metrics histogram
44+
SlowCacheThreshold = 30 * time.Millisecond
4245
)
4346

47+
// Test performs delete, put and get operations on a predefined key
48+
// returns
4449
func Test() (time.Duration, error) {
4550
if defaultCache == nil {
4651
return 0, fmt.Errorf("default cache not initialized")

modules/cache/cache_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ func TestTest(t *testing.T) {
4343
elapsed, err := Test()
4444
assert.NoError(t, err)
4545
// mem cache should take from 300ns up to 1ms on modern hardware ...
46-
assert.Less(t, elapsed, time.Millisecond)
46+
assert.Positive(t, elapsed)
47+
assert.Less(t, elapsed, SlowCacheThreshold)
4748
}
4849

4950
func TestGetCache(t *testing.T) {

0 commit comments

Comments
 (0)