Skip to content

Commit

Permalink
fix(cache): cache test triggered by non memory cache (#33220) (#33221)
Browse files Browse the repository at this point in the history
Backport #33220 by TheFox0x7

Change SlowCacheThreshold to 30 milliseconds so it doesn't trigger on
non memory cache

Closes: #33190
Closes: #32657

Co-authored-by: TheFox0x7 <[email protected]>
  • Loading branch information
GiteaBot and TheFox0x7 authored Jan 12, 2025
1 parent fcbbc24 commit 31f2a32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions modules/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ func Init() error {
}

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

// Test performs delete, put and get operations on a predefined key
// returns
func Test() (time.Duration, error) {
if defaultCache == nil {
return 0, fmt.Errorf("default cache not initialized")
Expand Down
3 changes: 2 additions & 1 deletion modules/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestTest(t *testing.T) {
elapsed, err := Test()
assert.NoError(t, err)
// mem cache should take from 300ns up to 1ms on modern hardware ...
assert.Less(t, elapsed, time.Millisecond)
assert.Positive(t, elapsed)
assert.Less(t, elapsed, SlowCacheThreshold)
}

func TestGetCache(t *testing.T) {
Expand Down

0 comments on commit 31f2a32

Please sign in to comment.