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

Unified Diff: cipd/client/cipd/internal/tagcache_test.go

Issue 2501023002: Add FileEntry cache to TagCache for selfupdate. (Closed)
Patch Set: fix comments Created 4 years, 1 month 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 | « cipd/client/cipd/internal/tagcache.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cipd/client/cipd/internal/tagcache_test.go
diff --git a/cipd/client/cipd/internal/tagcache_test.go b/cipd/client/cipd/internal/tagcache_test.go
index 4c9bf50c6ad60f18af3c9758406d79318a40e02f..89d496a5784064b5ab32c237e267bb7f9781aa1c 100644
--- a/cipd/client/cipd/internal/tagcache_test.go
+++ b/cipd/client/cipd/internal/tagcache_test.go
@@ -22,6 +22,16 @@ import (
func TestTagCacheWorks(t *testing.T) {
ctx := context.Background()
+ numberedID := func(i int) string {
+ return strings.Repeat(fmt.Sprintf("%02x", i), 20)
+ }
+ numberedPin := func(i int) common.Pin {
+ return common.Pin{
+ PackageName: "pkg",
+ InstanceID: numberedID(i),
+ }
+ }
+
Convey("with temp dir", t, func() {
tempDir, err := ioutil.TempDir("", "instanceche_test")
So(err, ShouldBeNil)
@@ -40,6 +50,10 @@ func TestTagCacheWorks(t *testing.T) {
So(err, ShouldBeNil)
So(pin, ShouldResemble, common.Pin{})
+ file, err := tc.ResolveFile(ctx, cannedPin, "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, "")
+
// Add new.
tc.AddTag(ctx, common.Pin{
PackageName: "pkg",
@@ -51,6 +65,10 @@ func TestTagCacheWorks(t *testing.T) {
PackageName: "pkg",
InstanceID: strings.Repeat("a", 40),
})
+ tc.AddFile(ctx, cannedPin, "filename", numberedID(1))
+ file, err = tc.ResolveFile(ctx, cannedPin, "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(1))
// Replace existing.
tc.AddTag(ctx, common.Pin{
@@ -63,6 +81,10 @@ func TestTagCacheWorks(t *testing.T) {
PackageName: "pkg",
InstanceID: strings.Repeat("b", 40),
})
+ tc.AddFile(ctx, cannedPin, "filename", numberedID(2))
+ file, err = tc.ResolveFile(ctx, cannedPin, "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(2))
// Save.
So(tc.Save(ctx), ShouldBeNil)
@@ -75,6 +97,9 @@ func TestTagCacheWorks(t *testing.T) {
PackageName: "pkg",
InstanceID: strings.Repeat("b", 40),
})
+ file, err = tc.ResolveFile(ctx, cannedPin, "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(2))
})
Convey("many tags", func() {
@@ -84,31 +109,47 @@ func TestTagCacheWorks(t *testing.T) {
for i := 0; i < tagCacheMaxSize; i++ {
So(tc.AddTag(ctx, cannedPin, fmt.Sprintf("tag:%d", i)), ShouldBeNil)
}
+ for i := 0; i < tagCacheMaxExeSize; i++ {
+ So(tc.AddFile(ctx, numberedPin(i), "filename", numberedID(i)), ShouldBeNil)
+ }
So(tc.Save(ctx), ShouldBeNil)
// Oldest tag is still resolvable.
pin, err := tc.ResolveTag(ctx, "pkg", "tag:0")
So(err, ShouldBeNil)
So(pin, ShouldResemble, cannedPin)
+ file, err := tc.ResolveFile(ctx, numberedPin(0), "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(0))
// Add one more tag. Should evict the oldest one.
So(tc.AddTag(ctx, cannedPin, "one_more_tag:0"), ShouldBeNil)
+ So(tc.AddFile(ctx, numberedPin(tagCacheMaxExeSize), "filename", numberedID(tagCacheMaxExeSize)), ShouldBeNil)
So(tc.Save(ctx), ShouldBeNil)
// Oldest tag is evicted.
pin, err = tc.ResolveTag(ctx, "pkg", "tag:0")
So(err, ShouldBeNil)
So(pin, ShouldResemble, common.Pin{})
+ file, err = tc.ResolveFile(ctx, numberedPin(0), "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, "")
// But next one is alive.
pin, err = tc.ResolveTag(ctx, "pkg", "tag:1")
So(err, ShouldBeNil)
So(pin, ShouldResemble, cannedPin)
+ file, err = tc.ResolveFile(ctx, numberedPin(1), "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(1))
// Most recent one is also alive.
pin, err = tc.ResolveTag(ctx, "pkg", "one_more_tag:0")
So(err, ShouldBeNil)
So(pin, ShouldResemble, cannedPin)
+ file, err = tc.ResolveFile(ctx, numberedPin(tagCacheMaxExeSize), "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(tagCacheMaxExeSize))
})
Convey("parallel update", func() {
@@ -116,7 +157,9 @@ func TestTagCacheWorks(t *testing.T) {
tc2 := NewTagCache(fs)
So(tc1.AddTag(ctx, cannedPin, "tag:1"), ShouldBeNil)
+ So(tc1.AddFile(ctx, numberedPin(0), "filename", numberedID(0)), ShouldBeNil)
So(tc2.AddTag(ctx, cannedPin, "tag:2"), ShouldBeNil)
+ So(tc2.AddFile(ctx, numberedPin(1), "filename", numberedID(1)), ShouldBeNil)
So(tc1.Save(ctx), ShouldBeNil)
So(tc2.Save(ctx), ShouldBeNil)
@@ -127,9 +170,15 @@ func TestTagCacheWorks(t *testing.T) {
pin, err := tc3.ResolveTag(ctx, "pkg", "tag:1")
So(err, ShouldBeNil)
So(pin, ShouldResemble, cannedPin)
+ file, err := tc3.ResolveFile(ctx, numberedPin(0), "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(0))
pin, err = tc3.ResolveTag(ctx, "pkg", "tag:2")
So(err, ShouldBeNil)
So(pin, ShouldResemble, cannedPin)
+ file, err = tc3.ResolveFile(ctx, numberedPin(1), "filename")
+ So(err, ShouldBeNil)
+ So(file, ShouldEqual, numberedID(1))
})
})
}
« no previous file with comments | « cipd/client/cipd/internal/tagcache.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698