aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheFox0x7 <thefox0x7@gmail.com>2025-01-11 21:33:43 +0100
committerGitHub <noreply@github.com>2025-01-12 04:33:43 +0800
commit8c6d7076b700a27c9c220f86a6e1e0e0b53b7fed (patch)
treed362272e98e34ed6667fa49310f2471507e05166
parent5c150ce9b0c9df32ebeebacdc31f44a32dc7fa15 (diff)
downloadgitea-8c6d7076b700a27c9c220f86a6e1e0e0b53b7fed.tar.gz
gitea-8c6d7076b700a27c9c220f86a6e1e0e0b53b7fed.zip
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: https://github.com/go-gitea/gitea/issues/33190 Closes: https://github.com/go-gitea/gitea/issues/32657
-rw-r--r--modules/cache/cache.go9
-rw-r--r--modules/cache/cache_test.go3
2 files changed, 9 insertions, 3 deletions
diff --git a/modules/cache/cache.go b/modules/cache/cache.go
index b5400b0bd6..f7828e3cae 100644
--- a/modules/cache/cache.go
+++ b/modules/cache/cache.go
@@ -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")
diff --git a/modules/cache/cache_test.go b/modules/cache/cache_test.go
index d0352947a8..5408020306 100644
--- a/modules/cache/cache_test.go
+++ b/modules/cache/cache_test.go
@@ -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) {