Skip to content

Commit

Permalink
fix(cache): cache test triggered by non memory cache (#33220)
Browse files Browse the repository at this point in the history
Change SlowCacheThreshold to 30 milliseconds so it doesn't trigger on
non memory cache

Closes: #33190
Closes: #32657
  • Loading branch information
TheFox0x7 authored Jan 11, 2025
1 parent 5c150ce commit 8c6d707
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 8c6d707

Please sign in to comment.