loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PORT] Add cache test for admins (#31265)

* the cache was not refactored in Forgejo
* fix the test modifying a global variable

+8 -6
+6 -5
modules/cache/cache.go
··· 6 6 import ( 7 7 "fmt" 8 8 "strconv" 9 + "time" 9 10 10 11 "code.gitea.io/gitea/modules/setting" 11 12 ··· 46 47 ) 47 48 48 49 func Test() (time.Duration, error) { 49 - if defaultCache == nil { 50 + if conn == nil { 50 51 return 0, fmt.Errorf("default cache not initialized") 51 52 } 52 53 ··· 54 55 55 56 start := time.Now() 56 57 57 - if err := defaultCache.Delete(testCacheKey); err != nil { 58 + if err := conn.Delete(testCacheKey); err != nil { 58 59 return 0, fmt.Errorf("expect cache to delete data based on key if exist but got: %w", err) 59 60 } 60 - if err := defaultCache.Put(testCacheKey, testData, 10); err != nil { 61 + if err := conn.Put(testCacheKey, testData, 10); err != nil { 61 62 return 0, fmt.Errorf("expect cache to store data but got: %w", err) 62 63 } 63 - testVal, hit := defaultCache.Get(testCacheKey) 64 - if !hit { 64 + testVal := conn.Get(testCacheKey) 65 + if testVal == nil { 65 66 return 0, fmt.Errorf("expect cache hit but got none") 66 67 } 67 68 if testVal != testData {
+2 -1
modules/cache/cache_test.go
··· 9 9 "time" 10 10 11 11 "code.gitea.io/gitea/modules/setting" 12 + "code.gitea.io/gitea/modules/test" 12 13 13 14 "github.com/stretchr/testify/assert" 14 15 ) ··· 35 36 } 36 37 37 38 func TestTest(t *testing.T) { 38 - defaultCache = nil 39 + defer test.MockVariableValue(&conn, nil)() 39 40 _, err := Test() 40 41 assert.Error(t, err) 41 42