Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(423)

Unified Diff: server/auth/cache_test.go

Issue 2646733008: server/auth: Add in-process LRU-based cache. (Closed)
Patch Set: Rename GlobalCache => Cache, ProcCache => MemoryCache. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « server/auth/cache.go ('k') | server/auth/config.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/auth/cache_test.go
diff --git a/server/auth/cache_test.go b/server/auth/cache_test.go
index c46732ec9ec177f445caf76f9eabfd7b719c7259..2376f28cfeaaac9017c035747ddfb5a0ba716bcc 100644
--- a/server/auth/cache_test.go
+++ b/server/auth/cache_test.go
@@ -21,13 +21,14 @@ import (
func TestTokenCache(t *testing.T) {
t.Parallel()
- Convey("with mocked cache", t, func() {
- cache := &mockedCache{}
+ Convey("with in-process cache", t, func() {
+ // Create a cache large enough that the LRU doesn't cycle.
+ cache := MemoryCache(1024)
ctx := context.Background()
ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeUTC)
ctx = mathrand.Set(ctx, rand.New(rand.NewSource(12345)))
- ctx = SetConfig(ctx, Config{GlobalCache: cache})
+ ctx = SetConfig(ctx, Config{Cache: cache})
tc := tokenCache{
Kind: "testing",
@@ -52,10 +53,8 @@ func TestTokenCache(t *testing.T) {
So(err, ShouldBeNil)
So(itm, ShouldResemble, &tok)
- So(len(cache.data), ShouldEqual, 1)
- for key := range cache.data {
- So(key, ShouldEqual, "testing/1/na7cNnVNdP6Ydb9K9UIEST04OV8")
- }
+ pgc := cache.(memoryCache)
+ So(pgc.cache.Len(), ShouldEqual, 1)
})
Convey("check expiration randomization", func() {
@@ -95,20 +94,3 @@ func TestTokenCache(t *testing.T) {
})
})
}
-
-// mockedCache is GlobalCache implementation for tests.
-type mockedCache struct {
- data map[string][]byte
-}
-
-func (mc *mockedCache) Get(c context.Context, key string) ([]byte, error) {
- return mc.data[key], nil
-}
-
-func (mc *mockedCache) Set(c context.Context, key string, value []byte, exp time.Duration) error {
- if mc.data == nil {
- mc.data = map[string][]byte{}
- }
- mc.data[key] = value
- return nil
-}
« no previous file with comments | « server/auth/cache.go ('k') | server/auth/config.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698