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

Unified Diff: luci_config/server/cfgclient/backend/caching/proccache_test.go

Issue 2573403002: server/config: Generic caching backend. (Closed)
Patch Set: Updated interface, rebased 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 | « luci_config/server/cfgclient/backend/caching/proccache.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: luci_config/server/cfgclient/backend/caching/proccache_test.go
diff --git a/luci_config/server/cfgclient/backend/caching/proccache_test.go b/luci_config/server/cfgclient/backend/caching/proccache_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..611536e0c3071f9184325cf0d57727affe610edf
--- /dev/null
+++ b/luci_config/server/cfgclient/backend/caching/proccache_test.go
@@ -0,0 +1,82 @@
+// Copyright 2015 The LUCI Authors. All rights reserved.
+// Use of this source code is governed under the Apache License, Version 2.0
+// that can be found in the LICENSE file.
+
+package caching
+
+import (
+ "testing"
+ "time"
+
+ "github.com/luci/luci-go/common/clock/testclock"
+ "github.com/luci/luci-go/common/config/impl/memory"
+ "github.com/luci/luci-go/common/data/caching/proccache"
+ "github.com/luci/luci-go/luci_config/server/cfgclient"
+ "github.com/luci/luci-go/luci_config/server/cfgclient/backend"
+ "github.com/luci/luci-go/luci_config/server/cfgclient/backend/client"
+ "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig"
+
+ "golang.org/x/net/context"
+
+ //. "github.com/luci/luci-go/common/testing/assertions"
+ . "github.com/smartystreets/goconvey/convey"
+)
+
+func TestProcCache(t *testing.T) {
+ t.Parallel()
+
+ Convey(`A testing setup`, t, func() {
+ c := context.Background()
+ c, tc := testclock.UseTime(c, testclock.TestTimeLocal)
+
+ mbase := map[string]memory.ConfigSet{
+ "projects/foo": {
+ "file": "content",
+ },
+ }
+
+ var pc proccache.Cache
+ c = proccache.Use(c, &pc)
+
+ // Install our backend: memory backed by cache backed by force error.
+ var be backend.B
+ lcp := testconfig.Provider{
+ Base: memory.New(mbase),
+ }
+ be = &client.Backend{
+ Provider: &lcp,
+ }
+ be = ProcCache(be, time.Hour)
+ c = backend.WithBackend(c, be)
+
+ Convey(`Will store and cache a value.`, func() {
+ var s string
+ So(cfgclient.Get(c, cfgclient.AsService, "projects/foo", "file", cfgclient.String(&s), nil), ShouldBeNil)
+ So(s, ShouldEqual, "content")
+
+ delete(mbase, "projects/foo")
+
+ // Cached.
+ So(cfgclient.Get(c, cfgclient.AsService, "projects/foo", "file", cfgclient.String(&s), nil), ShouldBeNil)
+ So(s, ShouldEqual, "content")
+
+ // Expires, records lack of config.
+ tc.Add(time.Hour)
+
+ So(cfgclient.Get(c, cfgclient.AsService, "projects/foo", "file", cfgclient.String(&s), nil),
+ ShouldEqual, cfgclient.ErrNoConfig)
+
+ // Re-add, still no config.
+ mbase["projects/foo"] = memory.ConfigSet{
+ "file": "content",
+ }
+ So(cfgclient.Get(c, cfgclient.AsService, "projects/foo", "file", cfgclient.String(&s), nil),
+ ShouldEqual, cfgclient.ErrNoConfig)
+
+ // "No config" expires, config is back.
+ tc.Add(time.Hour)
+ So(cfgclient.Get(c, cfgclient.AsService, "projects/foo", "file", cfgclient.String(&s), nil), ShouldBeNil)
+ So(s, ShouldEqual, "content")
+ })
+ })
+}
« no previous file with comments | « luci_config/server/cfgclient/backend/caching/proccache.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698