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

Unified Diff: logdog/common/storage/archive/storage_test.go

Issue 2435113002: LogDog: Add Storage-layer data caching. (Closed)
Patch Set: Fix byteLimit bug. Created 4 years, 2 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 | « logdog/common/storage/archive/storage.go ('k') | logdog/common/storage/bigtable/bigtable.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: logdog/common/storage/archive/storage_test.go
diff --git a/logdog/common/storage/archive/storage_test.go b/logdog/common/storage/archive/storage_test.go
index c774c3e45c1f0bc5bfc3f382463a2178f3dbd3d4..170646090d9cd367a2330dbe2d2ef21df0f33eb7 100644
--- a/logdog/common/storage/archive/storage_test.go
+++ b/logdog/common/storage/archive/storage_test.go
@@ -17,6 +17,7 @@ import (
"github.com/luci/luci-go/logdog/common/archive"
"github.com/luci/luci-go/logdog/common/renderer"
"github.com/luci/luci-go/logdog/common/storage"
+ "github.com/luci/luci-go/logdog/common/storage/memory"
cloudStorage "cloud.google.com/go/storage"
"github.com/golang/protobuf/proto"
@@ -313,13 +314,13 @@ func TestArchiveStorage(t *testing.T) {
title string
fn func() error
}{
- {"Get", func() error { return st.Get(storage.GetRequest{}, nil) }},
+ {"Get", func() error { return st.Get(storage.GetRequest{}, func(*storage.Entry) bool { return true }) }},
{"Tail", func() (err error) {
_, err = st.Tail("", "")
return
}},
} {
- Convey(fmt.Sprintf("Error case: %q", tc.title), func() {
+ Convey(fmt.Sprintf("Testing retrieval: %q", tc.title), func() {
Convey(`With missing log stream returns ErrDoesNotExist.`, func() {
stImpl.streamPath = "does-not-exist"
@@ -355,6 +356,34 @@ func TestArchiveStorage(t *testing.T) {
So(tc.fn(), ShouldErrLike, "failed to unmarshal")
})
+
+ Convey(`With data entries and a cache, only loads the index once.`, func() {
+ var cache memory.Cache
+ stImpl.Cache = &cache
+
+ gen.generate("foo", "bar", "baz", "qux", "quux")
+ client.load(&gen)
+
+ // Assert that an attempted load will fail with an error. This is so
+ // we don't accidentally test something that doesn't follow the path
+ // we're intending to follow.
+ client.indexErr = errors.New("not using a cache")
+ So(errors.Unwrap(tc.fn()), ShouldEqual, client.indexErr)
+
+ for i := 0; i < 10; i++ {
+ if i == 0 {
+ // First time successfully reads the index.
+ client.indexErr = nil
+ } else {
+ // Subsequent attempts to load the index will result in an error.
+ // This ensures that if they are successful, it's because we're
+ // hitting the cache.
+ client.indexErr = errors.New("not using a cache")
+ }
+
+ So(tc.fn(), ShouldBeNil)
+ }
+ })
})
}
« no previous file with comments | « logdog/common/storage/archive/storage.go ('k') | logdog/common/storage/bigtable/bigtable.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698