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

Unified Diff: server/auth/delegation_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/config.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/auth/delegation_test.go
diff --git a/server/auth/delegation_test.go b/server/auth/delegation_test.go
index 6d389f21b227c67d12a80c7c9c5caa66cedda026..5b6c2f432a7d0a995da8e1911ba9e16353d6eb40 100644
--- a/server/auth/delegation_test.go
+++ b/server/auth/delegation_test.go
@@ -30,7 +30,8 @@ func TestMintDelegationToken(t *testing.T) {
ctx, _ = testclock.UseTime(ctx, testclock.TestRecentTimeUTC)
ctx = mathrand.Set(ctx, rand.New(rand.NewSource(12345)))
- tokenCache := &mockedCache{}
+ // Create an LRU large enough that it will never cycle during test.
+ tokenCache := MemoryCache(1024)
subtokenID := "123"
mintingReq := ""
@@ -54,7 +55,7 @@ func TestMintDelegationToken(t *testing.T) {
ctx = ModifyConfig(ctx, func(cfg *Config) {
cfg.AccessTokenProvider = transport.getAccessToken
cfg.AnonymousTransport = transport.getTransport
- cfg.GlobalCache = tokenCache
+ cfg.Cache = tokenCache
cfg.Signer = signingtest.NewSigner(0, &signing.ServiceInfo{
ServiceAccountName: "service@example.com",
})
@@ -83,10 +84,9 @@ func TestMintDelegationToken(t *testing.T) {
`"impersonate":"user:abc@example.com","intent":"intent"}`)
// Cached now.
- So(len(tokenCache.data), ShouldEqual, 1)
- for k := range tokenCache.data {
- So(k, ShouldEqual, "delegation/2/R5RJ9yppAB8IK0GNB-UyjVrYoBw")
- }
+ So(tokenCache.(memoryCache).cache.Len(), ShouldEqual, 1)
+ v, _ := tokenCache.Get(ctx, "delegation/2/R5RJ9yppAB8IK0GNB-UyjVrYoBw")
+ So(v, ShouldNotBeNil)
// On subsequence request the cached token is used.
subtokenID = "456"
@@ -127,10 +127,9 @@ func TestMintDelegationToken(t *testing.T) {
`"impersonate":"user:abc@example.com","intent":"intent"}`)
// Cached now.
- So(len(tokenCache.data), ShouldEqual, 1)
- for k := range tokenCache.data {
- So(k, ShouldEqual, "delegation/2/tjYIGNrwFvKa0FT5juu7ThjpxBo")
- }
+ So(tokenCache.(memoryCache).cache.Len(), ShouldEqual, 1)
+ v, _ := tokenCache.Get(ctx, "delegation/2/tjYIGNrwFvKa0FT5juu7ThjpxBo")
+ So(v, ShouldNotBeNil)
})
})
}
« no previous file with comments | « server/auth/config.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698