Skip to content

Commit 31f2a32

Browse files
GiteaBotTheFox0x7
andauthored
fix(cache): cache test triggered by non memory cache (#33220) (#33221)
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]>
1 parent fcbbc24 commit 31f2a32

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

modules/cache/cache.go

+7-2
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

+2-1
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)