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

Side by Side Diff: go/buildbot/buildbot_test.go

Issue 796883002: buildbot package: actually find commits for each build during ingestion (Closed) Base URL: https://skia.googlesource.com/buildbot@master
Patch Set: Created 6 years 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 unified diff | Download patch
« no previous file with comments | « no previous file | go/buildbot/db.go » ('j') | go/buildbot/testdata/default_build.json » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 package buildbot 1 package buildbot
2 2
3 import ( 3 import (
4 "bytes" 4 "bytes"
5 "encoding/json" 5 "encoding/json"
6 "fmt" 6 "fmt"
7 "io" 7 "io"
8 "net/http" 8 "net/http"
9 "path/filepath"
9 "reflect" 10 "reflect"
10 "testing" 11 "testing"
11 12
12 "github.com/golang/glog" 13 "github.com/golang/glog"
13 14
14 "skia.googlesource.com/buildbot.git/go/database" 15 "skia.googlesource.com/buildbot.git/go/database"
16 "skia.googlesource.com/buildbot.git/go/gitinfo"
15 "skia.googlesource.com/buildbot.git/go/testutils" 17 "skia.googlesource.com/buildbot.git/go/testutils"
18 "skia.googlesource.com/buildbot.git/go/util"
16 ) 19 )
17 20
18 var ( 21 var (
19 // testJsonInput is raw JSON data as returned from the build master. 22 // testJsonInput is raw JSON data as returned from the build master.
20 testJsonInput = testutils.MustReadFile("default_build.json") 23 testJsonInput = testutils.MustReadFile("default_build.json")
21 24
22 // testIncompleteBuild is JSON data for a not-yet-finished build. 25 // testIncompleteBuild is JSON data for a not-yet-finished build.
23 testIncompleteBuild = testutils.MustReadFile("unfinished_build.json") 26 testIncompleteBuild = testutils.MustReadFile("unfinished_build.json")
24 27
25 // Results for /json/builders on various masters. 28 // Results for /json/builders on various masters.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 if data, ok := urlMap[url]; ok { 92 if data, ok := urlMap[url]; ok {
90 return &http.Response{ 93 return &http.Response{
91 Body: &respBodyCloser{bytes.NewReader(data)}, 94 Body: &respBodyCloser{bytes.NewReader(data)},
92 }, nil 95 }, nil
93 } 96 }
94 return nil, fmt.Errorf("No such URL in urlMap!") 97 return nil, fmt.Errorf("No such URL in urlMap!")
95 } 98 }
96 99
97 // testGetBuild is a helper function which pretends to load JSON data from a 100 // testGetBuild is a helper function which pretends to load JSON data from a
98 // build master and decodes it into a Build object. 101 // build master and decodes it into a Build object.
99 func testGetBuildFromMaster() (*Build, error) { 102 func testGetBuildFromMaster(repo *gitinfo.GitInfo) (*Build, error) {
100 httpGet = testGet 103 httpGet = testGet
101 » return GetBuildFromMaster("client.skia", "Test-Ubuntu12-ShuttleA-GTX660- x86-Release", 721) 104 » return getBuildFromMaster("client.skia", "Test-Ubuntu12-ShuttleA-GTX660- x86-Release", 721, repo)
102 } 105 }
103 106
104 // TestGetBuildFromMaster verifies that we can load JSON data from the build mas ter and 107 // TestGetBuildFromMaster verifies that we can load JSON data from the build mas ter and
105 // decode it into a Build object. 108 // decode it into a Build object.
106 func TestGetBuildFromMaster(t *testing.T) { 109 func TestGetBuildFromMaster(t *testing.T) {
110 clearDB(t, ProdDatabaseConfig(true))
borenet 2014/12/11 16:34:23 Now that ingesting a build runs findCommitsForBuil
111
112 // Load the test repo.
113 tr := util.NewTempRepo()
114 defer tr.Cleanup()
115 repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
116 if err != nil {
117 t.Fatal(err)
118 }
119
107 // Default, complete build. 120 // Default, complete build.
108 » if _, err := testGetBuildFromMaster(); err != nil { 121 » if _, err := testGetBuildFromMaster(repo); err != nil {
109 t.Fatal(err) 122 t.Fatal(err)
110 } 123 }
111 // Incomplete build. 124 // Incomplete build.
112 » _, err := GetBuildFromMaster("client.skia", "Test-Ubuntu12-ShuttleA-GTX5 50Ti-x86_64-Release-Valgrind", 152) 125 » _, err = getBuildFromMaster("client.skia", "Test-Ubuntu12-ShuttleA-GTX55 0Ti-x86_64-Release-Valgrind", 152, repo)
113 if err != nil { 126 if err != nil {
114 t.Fatal(err) 127 t.Fatal(err)
115 } 128 }
116 } 129 }
117 130
118 // TestBuildJsonSerialization verifies that we can serialize a build to JSON 131 // TestBuildJsonSerialization verifies that we can serialize a build to JSON
119 // and back without losing or corrupting the data. 132 // and back without losing or corrupting the data.
120 func TestBuildJsonSerialization(t *testing.T) { 133 func TestBuildJsonSerialization(t *testing.T) {
121 » b1, err := testGetBuildFromMaster() 134 » if err := clearDB(t, ProdDatabaseConfig(true)); err != nil {
135 » » t.Fatal(err)
136 » }
137
138 » // Load the test repo.
139 » tr := util.NewTempRepo()
140 » defer tr.Cleanup()
141 » repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
122 if err != nil { 142 if err != nil {
123 t.Fatal(err) 143 t.Fatal(err)
124 } 144 }
145
146 b1, err := testGetBuildFromMaster(repo)
147 if err != nil {
148 t.Fatal(err)
149 }
125 bytes, err := json.Marshal(b1) 150 bytes, err := json.Marshal(b1)
126 if err != nil { 151 if err != nil {
127 t.Fatal(err) 152 t.Fatal(err)
128 } 153 }
129 b2 := &Build{} 154 b2 := &Build{}
130 if err := json.Unmarshal(bytes, b2); err != nil { 155 if err := json.Unmarshal(bytes, b2); err != nil {
131 t.Fatal(err) 156 t.Fatal(err)
132 } 157 }
133 if !reflect.DeepEqual(b1, b2) { 158 if !reflect.DeepEqual(b1, b2) {
134 t.Fatalf("Serialization diff:\nIn: %v\nOut: %v", b1, b2) 159 t.Fatalf("Serialization diff:\nIn: %v\nOut: %v", b1, b2)
135 } 160 }
136 } 161 }
137 162
163 // TestFindCommitsForBuild verifies that findCommitsForBuild correctly obtains
164 // the list of commits which were newly built in a given build.
165 func TestFindCommitsForBuild(t *testing.T) {
166 if err := clearDB(t, ProdDatabaseConfig(true)); err != nil {
167 t.Fatal(err)
168 }
169
170 // Load the test repo.
171 tr := util.NewTempRepo()
172 defer tr.Cleanup()
173 repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
174 if err != nil {
175 t.Fatal(err)
176 }
177
178 // The test repo is laid out like this:
179 //
180 // * 06eb2a58139d3ff764f10232d5c8f9362d55e20f I (HEAD, master, Build # 4)
181 // * ecb424466a4f3b040586a062c15ed58356f6590e F (Build #3)
182 // |\
183 // | * d30286d2254716d396073c177a754f9e152bbb52 H
184 // | * 8d2d1247ef5d2b8a8d3394543df6c12a85881296 G (Build #2)
185 // * | 67635e7015d74b06c00154f7061987f426349d9f E
186 // * | 6d4811eddfa637fac0852c3a0801b773be1f260d D (Build #1)
187 // * | d74dfd42a48325ab2f3d4a97278fc283036e0ea4 C
188 // |/
189 // * 4b822ebb7cedd90acbac6a45b897438746973a87 B (Build #0)
190 // * 051955c355eb742550ddde4eccc3e90b6dc5b887 A
191 //
192 hashes := map[rune]string{
193 'A': "051955c355eb742550ddde4eccc3e90b6dc5b887",
194 'B': "4b822ebb7cedd90acbac6a45b897438746973a87",
195 'C': "d74dfd42a48325ab2f3d4a97278fc283036e0ea4",
196 'D': "6d4811eddfa637fac0852c3a0801b773be1f260d",
197 'E': "67635e7015d74b06c00154f7061987f426349d9f",
198 'F': "ecb424466a4f3b040586a062c15ed58356f6590e",
199 'G': "8d2d1247ef5d2b8a8d3394543df6c12a85881296",
200 'H': "d30286d2254716d396073c177a754f9e152bbb52",
201 'I': "06eb2a58139d3ff764f10232d5c8f9362d55e20f",
202 }
203
204 // Test cases. Each test case builds on the previous cases.
205 testCases := []struct {
206 GotRevision string
207 Expected []string
208 }{
209 // 0. The first build.
210 {
211 GotRevision: hashes['B'],
212 Expected: []string{hashes['B'], hashes['A']},
213 },
214 // 1. On a linear set of commits, with at least one previous bui ld.
215 {
216 GotRevision: hashes['D'],
217 Expected: []string{hashes['D'], hashes['C']},
218 },
219 // 2. The first build on a new branch.
220 {
221 GotRevision: hashes['G'],
222 Expected: []string{hashes['G']},
223 },
224 // 3. After a merge.
225 {
226 GotRevision: hashes['F'],
227 Expected: []string{hashes['F'], hashes['E'], hashes[' H']},
228 },
229 // 4. One last "normal" build.
230 {
231 GotRevision: hashes['I'],
232 Expected: []string{hashes['I']},
233 },
234 // 5. No GotRevision.
235 {
236 GotRevision: "",
237 Expected: []string{},
238 },
239 }
240 for buildNum, tc := range testCases {
241 b, err := testGetBuildFromMaster(repo)
242 if err != nil {
243 t.Fatal(err)
244 }
245 b.GotRevision = tc.GotRevision
246 b.Number = buildNum
247 c, err := findCommitsForBuild(b, repo)
248 if err != nil {
249 t.Fatal(err)
250 }
251 if !reflect.DeepEqual(c, tc.Expected) {
252 t.Fatalf("Commits for build do not match expectation.\nG ot: %v\nWant: %v", c, tc.Expected)
253 }
254 b.Commits = c
255 if err := b.ReplaceIntoDB(); err != nil {
256 t.Fatal(err)
257 }
258 }
259 }
260
138 // dbSerializeAndCompare is a helper function used by TestDbBuild which takes 261 // dbSerializeAndCompare is a helper function used by TestDbBuild which takes
139 // a Build object, writes it into the database, reads it back out, and compares 262 // a Build object, writes it into the database, reads it back out, and compares
140 // the structs. Returns any errors encountered including a comparison failure. 263 // the structs. Returns any errors encountered including a comparison failure.
141 func dbSerializeAndCompare(b1 *Build) error { 264 func dbSerializeAndCompare(b1 *Build) error {
142 if err := b1.ReplaceIntoDB(); err != nil { 265 if err := b1.ReplaceIntoDB(); err != nil {
143 return err 266 return err
144 } 267 }
145 b2, err := GetBuildFromDB(b1.MasterName, b1.BuilderName, b1.Number) 268 b2, err := GetBuildFromDB(b1.MasterName, b1.BuilderName, b1.Number)
146 if err != nil { 269 if err != nil {
147 return err 270 return err
148 } 271 }
149 272
150 if !reflect.DeepEqual(b1, b2) { 273 if !reflect.DeepEqual(b1, b2) {
151 for i, s := range b1.Steps { 274 for i, s := range b1.Steps {
152 if !reflect.DeepEqual(s, b2.Steps[i]) { 275 if !reflect.DeepEqual(s, b2.Steps[i]) {
153 glog.Errorf("Not equal:\n %+v\n %+v\n", s, b2.St eps[i]) 276 glog.Errorf("Not equal:\n %+v\n %+v\n", s, b2.St eps[i])
154 } 277 }
155 } 278 }
156 return fmt.Errorf("Builds are not equal! Builds:\nExpected: %+v\ nActual: %+v", b1, b2) 279 return fmt.Errorf("Builds are not equal! Builds:\nExpected: %+v\ nActual: %+v", b1, b2)
157 } 280 }
158 return nil 281 return nil
159 } 282 }
160 283
161 // testBuildDbSerialization verifies that we can write a build to the DB and 284 // testBuildDbSerialization verifies that we can write a build to the DB and
162 // pull it back out without losing or corrupting the data. 285 // pull it back out without losing or corrupting the data.
163 func testBuildDbSerialization(t *testing.T, conf *database.DatabaseConfig) { 286 func testBuildDbSerialization(t *testing.T, conf *database.DatabaseConfig) {
164 clearDB(t, conf) 287 clearDB(t, conf)
288 // Load the test repo.
289 tr := util.NewTempRepo()
290 defer tr.Cleanup()
291 repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
292 if err != nil {
293 t.Fatal(err)
294 }
165 295
166 // Test case: an empty build. Tests null and empty values. 296 // Test case: an empty build. Tests null and empty values.
167 emptyTime := 0.0 297 emptyTime := 0.0
168 emptyBuild := &Build{ 298 emptyBuild := &Build{
169 Steps: []*BuildStep{}, 299 Steps: []*BuildStep{},
170 Times: []float64{emptyTime, emptyTime}, 300 Times: []float64{emptyTime, emptyTime},
171 Commits: []string{}, 301 Commits: []string{},
172 } 302 }
173 303
174 // Test case: a completely filled-out build. 304 // Test case: a completely filled-out build.
175 » buildFromFullJson, err := testGetBuildFromMaster() 305 » buildFromFullJson, err := testGetBuildFromMaster(repo)
176 if err != nil { 306 if err != nil {
177 t.Fatal(err) 307 t.Fatal(err)
178 } 308 }
179 // TODO(borenet): Remove this once we actually associate commits with bu ilds.
180 buildFromFullJson.Commits = []string{
181 "1e7841f2a7a06065e926d6544e833f400fec9d6e",
182 "3209f6591512980197d410ac1e6139a5e4731a38",
183 "b578bd76143927ac14981c2ee235b06366b10e7f",
184 }
185 309
186 testCases := []*Build{emptyBuild, buildFromFullJson} 310 testCases := []*Build{emptyBuild, buildFromFullJson}
187 for _, b := range testCases { 311 for _, b := range testCases {
188 if err = dbSerializeAndCompare(b); err != nil { 312 if err = dbSerializeAndCompare(b); err != nil {
189 t.Fatal(err) 313 t.Fatal(err)
190 } 314 }
191 } 315 }
192 } 316 }
193 317
194 // testUnfinishedBuild verifies that we can write a build which is not yet 318 // testUnfinishedBuild verifies that we can write a build which is not yet
195 // finished, load the build back from the database, and update it when it 319 // finished, load the build back from the database, and update it when it
196 // finishes. 320 // finishes.
197 func testUnfinishedBuild(t *testing.T, conf *database.DatabaseConfig) { 321 func testUnfinishedBuild(t *testing.T, conf *database.DatabaseConfig) {
198 clearDB(t, conf) 322 clearDB(t, conf)
323 // Load the test repo.
324 tr := util.NewTempRepo()
325 defer tr.Cleanup()
326 repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
327 if err != nil {
328 t.Fatal(err)
329 }
199 330
200 // Obtain and insert an unfinished build. 331 // Obtain and insert an unfinished build.
201 httpGet = testGet 332 httpGet = testGet
202 » b, err := GetBuildFromMaster("client.skia", "Test-Ubuntu12-ShuttleA-GTX5 50Ti-x86_64-Release-Valgrind", 152) 333 » b, err := getBuildFromMaster("client.skia", "Test-Ubuntu12-ShuttleA-GTX5 50Ti-x86_64-Release-Valgrind", 152, repo)
203 if err != nil { 334 if err != nil {
204 t.Fatal(err) 335 t.Fatal(err)
205 } 336 }
206 if b.IsFinished() { 337 if b.IsFinished() {
207 t.Fatal(fmt.Errorf("Unfinished build thinks it's finished!")) 338 t.Fatal(fmt.Errorf("Unfinished build thinks it's finished!"))
208 } 339 }
209 if err := dbSerializeAndCompare(b); err != nil { 340 if err := dbSerializeAndCompare(b); err != nil {
210 t.Fatal(err) 341 t.Fatal(err)
211 } 342 }
212 343
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 } 396 }
266 if found { 397 if found {
267 t.Fatal(fmt.Errorf("Finished build was found by getUnfinishedBui lds!")) 398 t.Fatal(fmt.Errorf("Finished build was found by getUnfinishedBui lds!"))
268 } 399 }
269 } 400 }
270 401
271 // testLastProcessedBuilds verifies that getLastProcessedBuilds gives us 402 // testLastProcessedBuilds verifies that getLastProcessedBuilds gives us
272 // the expected result. 403 // the expected result.
273 func testLastProcessedBuilds(t *testing.T, conf *database.DatabaseConfig) { 404 func testLastProcessedBuilds(t *testing.T, conf *database.DatabaseConfig) {
274 clearDB(t, conf) 405 clearDB(t, conf)
275 » build, err := testGetBuildFromMaster() 406 » // Load the test repo.
407 » tr := util.NewTempRepo()
408 » defer tr.Cleanup()
409 » repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
276 if err != nil { 410 if err != nil {
277 t.Fatal(err) 411 t.Fatal(err)
278 } 412 }
413
414 build, err := testGetBuildFromMaster(repo)
415 if err != nil {
416 t.Fatal(err)
417 }
279 418
280 // Ensure that we get the right number for not-yet-processed 419 // Ensure that we get the right number for not-yet-processed
281 // builder/master pair. 420 // builder/master pair.
282 builds, err := getLastProcessedBuilds() 421 builds, err := getLastProcessedBuilds()
283 if err != nil { 422 if err != nil {
284 t.Fatal(err) 423 t.Fatal(err)
285 } 424 }
286 if builds == nil || len(builds) != 0 { 425 if builds == nil || len(builds) != 0 {
287 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned an unaccepta ble value for no builds: %v", builds)) 426 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned an unaccepta ble value for no builds: %v", builds))
288 } 427 }
289 428
290 // Ensure that we get the right number for a single already-processed 429 // Ensure that we get the right number for a single already-processed
291 // builder/master pair. 430 // builder/master pair.
292 if err := build.ReplaceIntoDB(); err != nil { 431 if err := build.ReplaceIntoDB(); err != nil {
293 t.Fatal(err) 432 t.Fatal(err)
294 } 433 }
295 builds, err = getLastProcessedBuilds() 434 builds, err = getLastProcessedBuilds()
296 if err != nil { 435 if err != nil {
297 t.Fatal(err) 436 t.Fatal(err)
298 } 437 }
299 if builds == nil || len(builds) != 1 { 438 if builds == nil || len(builds) != 1 {
300 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned incorrect nu mber of results: %v", builds)) 439 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned incorrect nu mber of results: %v", builds))
301 } 440 }
302 if builds[0].MasterName != build.MasterName || builds[0].BuilderName != build.BuilderName || builds[0].Number != build.Number { 441 if builds[0].MasterName != build.MasterName || builds[0].BuilderName != build.BuilderName || builds[0].Number != build.Number {
303 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned the wrong bu ild: %v", builds[0])) 442 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned the wrong bu ild: %v", builds[0]))
304 } 443 }
305 444
306 // Ensure that we get the correct result for multiple builders. 445 // Ensure that we get the correct result for multiple builders.
307 » build2, err := testGetBuildFromMaster() 446 » build2, err := testGetBuildFromMaster(repo)
308 if err != nil { 447 if err != nil {
309 t.Fatal(err) 448 t.Fatal(err)
310 } 449 }
311 build2.BuilderName = "Other-Builder" 450 build2.BuilderName = "Other-Builder"
312 build2.Number = build.Number + 10 451 build2.Number = build.Number + 10
313 if err := build2.ReplaceIntoDB(); err != nil { 452 if err := build2.ReplaceIntoDB(); err != nil {
314 t.Fatal(err) 453 t.Fatal(err)
315 } 454 }
316 builds, err = getLastProcessedBuilds() 455 builds, err = getLastProcessedBuilds()
317 if err != nil { 456 if err != nil {
(...skipping 15 matching lines...) Expand all
333 return false 472 return false
334 } 473 }
335 } 474 }
336 return true 475 return true
337 } 476 }
338 if !compareBuildLists([]*Build{build, build2}, builds) { 477 if !compareBuildLists([]*Build{build, build2}, builds) {
339 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned incorrect re sults: %v", builds)) 478 t.Fatal(fmt.Errorf("getLastProcessedBuilds returned incorrect re sults: %v", builds))
340 } 479 }
341 480
342 // Add "older" build, ensure that only the newer ones are returned. 481 // Add "older" build, ensure that only the newer ones are returned.
343 » build3, err := testGetBuildFromMaster() 482 » build3, err := testGetBuildFromMaster(repo)
344 if err != nil { 483 if err != nil {
345 t.Fatal(err) 484 t.Fatal(err)
346 } 485 }
347 build3.Number -= 10 486 build3.Number -= 10
348 if err := build3.ReplaceIntoDB(); err != nil { 487 if err := build3.ReplaceIntoDB(); err != nil {
349 t.Fatal(err) 488 t.Fatal(err)
350 } 489 }
351 builds, err = getLastProcessedBuilds() 490 builds, err = getLastProcessedBuilds()
352 if err != nil { 491 if err != nil {
353 t.Fatal(err) 492 t.Fatal(err)
(...skipping 26 matching lines...) Expand all
380 if !reflect.DeepEqual(expected, actual) { 519 if !reflect.DeepEqual(expected, actual) {
381 t.Fatal(fmt.Errorf("getLatestBuilds returned incorrect results: %v", actual)) 520 t.Fatal(fmt.Errorf("getLatestBuilds returned incorrect results: %v", actual))
382 } 521 }
383 } 522 }
384 523
385 // testGetUningestedBuilds verifies that getUningestedBuilds works as expected. 524 // testGetUningestedBuilds verifies that getUningestedBuilds works as expected.
386 func testGetUningestedBuilds(t *testing.T, conf *database.DatabaseConfig) { 525 func testGetUningestedBuilds(t *testing.T, conf *database.DatabaseConfig) {
387 // First, insert some builds into the database as a starting point. 526 // First, insert some builds into the database as a starting point.
388 clearDB(t, conf) 527 clearDB(t, conf)
389 528
390 » // This builder is no longer found on the master. 529 » // Load the test repo.
391 » b1, err := testGetBuildFromMaster() 530 » tr := util.NewTempRepo()
531 » defer tr.Cleanup()
532 » repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
392 if err != nil { 533 if err != nil {
393 t.Fatal(err) 534 t.Fatal(err)
394 } 535 }
536
537 // This builder is no longer found on the master.
538 b1, err := testGetBuildFromMaster(repo)
539 if err != nil {
540 t.Fatal(err)
541 }
395 b1.MasterName = "client.skia.compile" 542 b1.MasterName = "client.skia.compile"
396 b1.BuilderName = "My-Builder" 543 b1.BuilderName = "My-Builder"
397 b1.Number = 115 544 b1.Number = 115
398 b1.Steps = []*BuildStep{} 545 b1.Steps = []*BuildStep{}
399 if err := b1.ReplaceIntoDB(); err != nil { 546 if err := b1.ReplaceIntoDB(); err != nil {
400 t.Fatal(err) 547 t.Fatal(err)
401 } 548 }
402 549
403 // This builder needs to load a few builds. 550 // This builder needs to load a few builds.
404 » b2, err := testGetBuildFromMaster() 551 » b2, err := testGetBuildFromMaster(repo)
405 if err != nil { 552 if err != nil {
406 t.Fatal(err) 553 t.Fatal(err)
407 } 554 }
408 b2.MasterName = "client.skia.android" 555 b2.MasterName = "client.skia.android"
409 b2.BuilderName = "Perf-Android-Venue8-PowerVR-x86-Release" 556 b2.BuilderName = "Perf-Android-Venue8-PowerVR-x86-Release"
410 b2.Number = 463 557 b2.Number = 463
411 b2.Steps = []*BuildStep{} 558 b2.Steps = []*BuildStep{}
412 if err := b2.ReplaceIntoDB(); err != nil { 559 if err := b2.ReplaceIntoDB(); err != nil {
413 t.Fatal(err) 560 t.Fatal(err)
414 } 561 }
415 562
416 // This builder is already up-to-date. 563 // This builder is already up-to-date.
417 » b3, err := testGetBuildFromMaster() 564 » b3, err := testGetBuildFromMaster(repo)
418 if err != nil { 565 if err != nil {
419 t.Fatal(err) 566 t.Fatal(err)
420 } 567 }
421 b3.MasterName = "client.skia.fyi" 568 b3.MasterName = "client.skia.fyi"
422 b3.BuilderName = "Housekeeper-PerCommit" 569 b3.BuilderName = "Housekeeper-PerCommit"
423 b3.Number = 1035 570 b3.Number = 1035
424 b3.Steps = []*BuildStep{} 571 b3.Steps = []*BuildStep{}
425 if err := b3.ReplaceIntoDB(); err != nil { 572 if err := b3.ReplaceIntoDB(); err != nil {
426 t.Fatal(err) 573 t.Fatal(err)
427 } 574 }
428 575
429 // This builder is already up-to-date. 576 // This builder is already up-to-date.
430 » b4, err := testGetBuildFromMaster() 577 » b4, err := testGetBuildFromMaster(repo)
431 if err != nil { 578 if err != nil {
432 t.Fatal(err) 579 t.Fatal(err)
433 } 580 }
434 b4.MasterName = "client.skia.android" 581 b4.MasterName = "client.skia.android"
435 b4.BuilderName = "Test-Android-Venue8-PowerVR-x86-Debug" 582 b4.BuilderName = "Test-Android-Venue8-PowerVR-x86-Debug"
436 b4.Number = 532 583 b4.Number = 532
437 b4.Steps = []*BuildStep{} 584 b4.Steps = []*BuildStep{}
438 if err := b4.ReplaceIntoDB(); err != nil { 585 if err := b4.ReplaceIntoDB(); err != nil {
439 t.Fatal(err) 586 t.Fatal(err)
440 } 587 }
(...skipping 22 matching lines...) Expand all
463 } 610 }
464 } 611 }
465 612
466 // testIngestNewBuilds verifies that we can successfully query the masters and 613 // testIngestNewBuilds verifies that we can successfully query the masters and
467 // the database for new and unfinished builds, respectively, and ingest them 614 // the database for new and unfinished builds, respectively, and ingest them
468 // into the database. 615 // into the database.
469 func testIngestNewBuilds(t *testing.T, conf *database.DatabaseConfig) { 616 func testIngestNewBuilds(t *testing.T, conf *database.DatabaseConfig) {
470 // First, insert some builds into the database as a starting point. 617 // First, insert some builds into the database as a starting point.
471 clearDB(t, conf) 618 clearDB(t, conf)
472 619
473 » // This builder needs to load a few builds. 620 » // Load the test repo.
474 » b1, err := testGetBuildFromMaster() 621 » tr := util.NewTempRepo()
622 » defer tr.Cleanup()
623 » repo, err := gitinfo.NewGitInfo(filepath.Join(tr.Dir, "testrepo"), false , true)
475 if err != nil { 624 if err != nil {
476 t.Fatal(err) 625 t.Fatal(err)
477 } 626 }
627
628 // This builder needs to load a few builds.
629 b1, err := testGetBuildFromMaster(repo)
630 if err != nil {
631 t.Fatal(err)
632 }
478 b1.MasterName = "client.skia.android" 633 b1.MasterName = "client.skia.android"
479 b1.BuilderName = "Perf-Android-Venue8-PowerVR-x86-Release" 634 b1.BuilderName = "Perf-Android-Venue8-PowerVR-x86-Release"
480 b1.Number = 463 635 b1.Number = 463
481 b1.Steps = []*BuildStep{} 636 b1.Steps = []*BuildStep{}
482 if err := b1.ReplaceIntoDB(); err != nil { 637 if err := b1.ReplaceIntoDB(); err != nil {
483 t.Fatal(err) 638 t.Fatal(err)
484 } 639 }
485 640
486 // This builder has no new builds, but the last one wasn't finished 641 // This builder has no new builds, but the last one wasn't finished
487 // at its time of ingestion. 642 // at its time of ingestion.
488 » b2, err := testGetBuildFromMaster() 643 » b2, err := testGetBuildFromMaster(repo)
489 if err != nil { 644 if err != nil {
490 t.Fatal(err) 645 t.Fatal(err)
491 } 646 }
492 b2.MasterName = "client.skia.fyi" 647 b2.MasterName = "client.skia.fyi"
493 b2.BuilderName = "Housekeeper-PerCommit" 648 b2.BuilderName = "Housekeeper-PerCommit"
494 b2.Number = 1035 649 b2.Number = 1035
495 b2.Finished = 0.0 650 b2.Finished = 0.0
496 b2.Steps = []*BuildStep{} 651 b2.Steps = []*BuildStep{}
497 if err := b2.ReplaceIntoDB(); err != nil { 652 if err := b2.ReplaceIntoDB(); err != nil {
498 t.Fatal(err) 653 t.Fatal(err)
499 } 654 }
500 655
501 // Subsequent builders are already up-to-date. 656 // Subsequent builders are already up-to-date.
502 » b3, err := testGetBuildFromMaster() 657 » b3, err := testGetBuildFromMaster(repo)
503 b3.MasterName = "client.skia.fyi" 658 b3.MasterName = "client.skia.fyi"
504 b3.BuilderName = "Housekeeper-Nightly-RecreateSKPs" 659 b3.BuilderName = "Housekeeper-Nightly-RecreateSKPs"
505 b3.Number = 58 660 b3.Number = 58
506 b3.Steps = []*BuildStep{} 661 b3.Steps = []*BuildStep{}
507 if err := b3.ReplaceIntoDB(); err != nil { 662 if err := b3.ReplaceIntoDB(); err != nil {
508 t.Fatal(err) 663 t.Fatal(err)
509 } 664 }
510 665
511 » b4, err := testGetBuildFromMaster() 666 » b4, err := testGetBuildFromMaster(repo)
512 if err != nil { 667 if err != nil {
513 t.Fatal(err) 668 t.Fatal(err)
514 } 669 }
515 b4.MasterName = "client.skia.android" 670 b4.MasterName = "client.skia.android"
516 b4.BuilderName = "Test-Android-Venue8-PowerVR-x86-Debug" 671 b4.BuilderName = "Test-Android-Venue8-PowerVR-x86-Debug"
517 b4.Number = 532 672 b4.Number = 532
518 b4.Steps = []*BuildStep{} 673 b4.Steps = []*BuildStep{}
519 if err := b4.ReplaceIntoDB(); err != nil { 674 if err := b4.ReplaceIntoDB(); err != nil {
520 t.Fatal(err) 675 t.Fatal(err)
521 } 676 }
522 677
523 // IngestNewBuilds should process the above Venue8 Perf bot's builds 678 // IngestNewBuilds should process the above Venue8 Perf bot's builds
524 // 464-466 as well as Housekeeper-PerCommit's unfinished build #1035. 679 // 464-466 as well as Housekeeper-PerCommit's unfinished build #1035.
525 » if err := IngestNewBuilds(); err != nil { 680 » if err := IngestNewBuilds(repo); err != nil {
526 t.Fatal(err) 681 t.Fatal(err)
527 } 682 }
528 683
529 // Verify that the expected builds are now in the database. 684 // Verify that the expected builds are now in the database.
530 expected := []Build{ 685 expected := []Build{
531 Build{ 686 Build{
532 MasterName: b1.MasterName, 687 MasterName: b1.MasterName,
533 BuilderName: b1.BuilderName, 688 BuilderName: b1.BuilderName,
534 Number: 464, 689 Number: 464,
535 }, 690 },
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 } 772 }
618 testGetUningestedBuilds(t, localMySQLTestDatabaseConfig("test_user", "") ) 773 testGetUningestedBuilds(t, localMySQLTestDatabaseConfig("test_user", "") )
619 } 774 }
620 775
621 func TestMySQLIngestNewBuilds(t *testing.T) { 776 func TestMySQLIngestNewBuilds(t *testing.T) {
622 if testing.Short() { 777 if testing.Short() {
623 t.Skip("Skipping MySQL tests with -short.") 778 t.Skip("Skipping MySQL tests with -short.")
624 } 779 }
625 testIngestNewBuilds(t, localMySQLTestDatabaseConfig("test_user", "")) 780 testIngestNewBuilds(t, localMySQLTestDatabaseConfig("test_user", ""))
626 } 781 }
OLDNEW
« no previous file with comments | « no previous file | go/buildbot/db.go » ('j') | go/buildbot/testdata/default_build.json » ('J')

Powered by Google App Engine
This is Rietveld 408576698