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

Unified Diff: build_scheduler/go/db/cache_test.go

Issue 2226583003: Add build scheduler DB interface, dumb in-memory impl, cache (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Address more comments Created 4 years, 4 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 | « build_scheduler/go/db/cache.go ('k') | build_scheduler/go/db/db.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e86cd601cf8f8897dc5f337b4309c10b5489bb39
--- /dev/null
+++ b/build_scheduler/go/db/cache_test.go
@@ -0,0 +1,60 @@
+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) {
+ 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.Builder: 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)
+
+ // Insert a build on a second bot.
+ b3 := makeBuild("build3", startTime.Add(2*time.Minute), []string{"a", "b"})
+ b3.Builder = "Another-Builder"
+ assert.NoError(t, db.PutBuild(b3))
+ assert.NoError(t, c.Update())
+ builds, err := c.GetBuildsForCommits([]string{"b"})
+ assert.NoError(t, err)
+ testutils.AssertDeepEqual(t, map[string]map[string]*Build{
+ "b": map[string]*Build{
+ b1.Builder: b1,
+ b3.Builder: b3,
+ },
+ }, builds)
+}
« no previous file with comments | « build_scheduler/go/db/cache.go ('k') | build_scheduler/go/db/db.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698