| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package caching |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 "time" |
| 10 |
| 11 "github.com/luci/luci-go/common/clock/testclock" |
| 12 "github.com/luci/luci-go/common/config/impl/memory" |
| 13 "github.com/luci/luci-go/common/data/caching/proccache" |
| 14 "github.com/luci/luci-go/server/config" |
| 15 "github.com/luci/luci-go/server/config/testconfig" |
| 16 |
| 17 "golang.org/x/net/context" |
| 18 |
| 19 //. "github.com/luci/luci-go/common/testing/assertions" |
| 20 . "github.com/smartystreets/goconvey/convey" |
| 21 ) |
| 22 |
| 23 func TestProcCache(t *testing.T) { |
| 24 t.Parallel() |
| 25 |
| 26 Convey(`A testing setup`, t, func() { |
| 27 c := context.Background() |
| 28 c, tc := testclock.UseTime(c, testclock.TestTimeLocal) |
| 29 |
| 30 mbase := map[string]memory.ConfigSet{ |
| 31 "projects/foo": { |
| 32 "file": "content", |
| 33 }, |
| 34 } |
| 35 |
| 36 var pc proccache.Cache |
| 37 c = proccache.Use(c, &pc) |
| 38 |
| 39 // Install our backend: memory backed by cache backed by force e
rror. |
| 40 var backend config.Backend |
| 41 lcp := testconfig.LocalClientProvider{ |
| 42 Base: memory.New(mbase), |
| 43 } |
| 44 backend = &config.ClientBackend{ |
| 45 Provider: &lcp, |
| 46 } |
| 47 backend = ProcCache(backend, time.Hour) |
| 48 c = config.WithBackend(c, backend) |
| 49 |
| 50 Convey(`Will store and cache a value.`, func() { |
| 51 var s string |
| 52 So(config.Get(c, config.AsService, "projects/foo", "file
", config.String(&s), nil), ShouldBeNil) |
| 53 So(s, ShouldEqual, "content") |
| 54 |
| 55 delete(mbase, "projects/foo") |
| 56 |
| 57 // Cached. |
| 58 So(config.Get(c, config.AsService, "projects/foo", "file
", config.String(&s), nil), ShouldBeNil) |
| 59 So(s, ShouldEqual, "content") |
| 60 |
| 61 // Expires, records lack of config. |
| 62 tc.Add(time.Hour) |
| 63 |
| 64 So(config.Get(c, config.AsService, "projects/foo", "file
", config.String(&s), nil), |
| 65 ShouldEqual, config.ErrNoConfig) |
| 66 |
| 67 // Re-add, still no config. |
| 68 mbase["projects/foo"] = memory.ConfigSet{ |
| 69 "file": "content", |
| 70 } |
| 71 So(config.Get(c, config.AsService, "projects/foo", "file
", config.String(&s), nil), |
| 72 ShouldEqual, config.ErrNoConfig) |
| 73 |
| 74 // "No config" expires, config is back. |
| 75 tc.Add(time.Hour) |
| 76 So(config.Get(c, config.AsService, "projects/foo", "file
", config.String(&s), nil), ShouldBeNil) |
| 77 So(s, ShouldEqual, "content") |
| 78 }) |
| 79 }) |
| 80 } |
| OLD | NEW |