Index: build_scheduler/go/db/cache_test.go |
diff --git a/build_scheduler/go/db/cache_test.go b/build_scheduler/go/db/cache_test.go |
new file mode 100644 |
index 0000000000000000000000000000000000000000..63c0f6f2de7be7198c678e6ab476b04163d2fa66 |
--- /dev/null |
+++ b/build_scheduler/go/db/cache_test.go |
@@ -0,0 +1,46 @@ |
+package db |
+ |
+import ( |
+ "testing" |
+ "time" |
+ |
+ assert "github.com/stretchr/testify/require" |
+ "go.skia.org/infra/go/testutils" |
+) |
+ |
+func testGetBuildsForCommits(t *testing.T, c *BuildCache, b *Build) { |
dogben
2016/08/08 19:22:38
Is there any reason to test GetBuildsForCommits fo
borenet
2016/08/08 19:51:18
If ingestion is done correctly, we should never ha
dogben
2016/08/08 20:16:07
Sorry, I meant two builds for the same commit but
borenet
2016/08/09 11:22:55
Oh! Done.
|
+ for _, commit := range b.Commits { |
+ builds, err := c.GetBuildsForCommits([]string{commit}) |
+ assert.NoError(t, err) |
+ testutils.AssertDeepEqual(t, map[string]map[string]*Build{ |
+ commit: map[string]*Build{ |
+ b.Id: b, |
+ }, |
+ }, builds) |
+ } |
+} |
+ |
+func TestDBCache(t *testing.T) { |
+ db := NewInMemoryDB() |
+ defer testutils.AssertCloses(t, db) |
+ |
+ // Pre-load a build into the DB. |
+ startTime := time.Now().Add(-30 * time.Minute) // Arbitrary starting point. |
+ b1 := makeBuild("build1", startTime, []string{"a", "b", "c", "d"}) |
+ assert.NoError(t, db.PutBuild(b1)) |
+ |
+ // Create the cache. Ensure that the existing build is present. |
+ c, err := NewBuildCache(db, time.Hour) |
+ assert.NoError(t, err) |
+ testGetBuildsForCommits(t, c, b1) |
+ |
+ // Bisect the first build. |
+ b2 := makeBuild("build2", startTime.Add(time.Minute), []string{"c", "d"}) |
+ b1.Commits = []string{"a", "b"} |
+ assert.NoError(t, db.PutBuilds([]*Build{b2, b1})) |
+ assert.NoError(t, c.Update()) |
+ |
+ // Ensure that b2 (and not b1) shows up for commits "c" and "d". |
+ testGetBuildsForCommits(t, c, b1) |
+ testGetBuildsForCommits(t, c, b2) |
+} |