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

Side by Side Diff: milo/appengine/buildbot/pubsub_test.go

Issue 2406163003: Milo: Clean up builds that are no longer current. (Closed)
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « milo/appengine/buildbot/pubsub.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package buildbot 5 package buildbot
6 6
7 import ( 7 import (
8 "bytes" 8 "bytes"
9 "compress/zlib" 9 "compress/zlib"
10 "encoding/base64" 10 "encoding/base64"
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 }) 164 })
165 }) 165 })
166 166
167 Convey("Build panics on invalid query", func() { 167 Convey("Build panics on invalid query", func() {
168 build := &buildbotBuild{ 168 build := &buildbotBuild{
169 Master: "Fake Master", 169 Master: "Fake Master",
170 } 170 }
171 So(func() { ds.Put(c, build) }, ShouldPanicLike, "No Mas ter or Builder found") 171 So(func() { ds.Put(c, build) }, ShouldPanicLike, "No Mas ter or Builder found")
172 }) 172 })
173 173
174 ts := 555
174 b := &buildbotBuild{ 175 b := &buildbotBuild{
175 Master: "Fake Master", 176 Master: "Fake Master",
176 Buildername: "Fake buildername", 177 Buildername: "Fake buildername",
177 Number: 1234, 178 Number: 1234,
178 Currentstep: "this is a string", 179 Currentstep: "this is a string",
179 Times: buildbotTimesPending(123.0), 180 Times: buildbotTimesPending(123.0),
181 TimeStamp: &ts,
180 } 182 }
181 183
182 Convey("Basic master + build pusbsub subscription", func() { 184 Convey("Basic master + build pusbsub subscription", func() {
183 h := httptest.NewRecorder() 185 h := httptest.NewRecorder()
184 slaves := map[string]*buildbotSlave{} 186 slaves := map[string]*buildbotSlave{}
185 ft := 1234.0 187 ft := 1234.0
186 slaves["testslave"] = &buildbotSlave{ 188 slaves["testslave"] = &buildbotSlave{
187 Name: "testslave", 189 Name: "testslave",
188 Connected: true, 190 Connected: true,
189 Runningbuilds: []*buildbotBuild{ 191 Runningbuilds: []*buildbotBuild{
190 { 192 {
191 Master: "Fake Master", 193 Master: "Fake Master",
192 Buildername: "Fake buildername", 194 Buildername: "Fake buildername",
193 Number: 2222, 195 Number: 2222,
194 Times: []*float64{&ft, nil }, 196 Times: []*float64{&ft, nil },
195 }, 197 },
196 }, 198 },
197 } 199 }
198 ms := buildbotMaster{ 200 ms := buildbotMaster{
199 » » » » Name: "fakename", 201 » » » » Name: "Fake Master",
200 » » » » Project: buildbotProject{Title: "some title"}, 202 » » » » Project: buildbotProject{Title: "some title"},
201 » » » » Slaves: slaves, 203 » » » » Slaves: slaves,
204 » » » » Builders: map[string]*buildbotBuilder{},
205 » » » }
206
207 » » » ms.Builders["Fake buildername"] = &buildbotBuilder{
208 » » » » CurrentBuilds: []int{1234},
202 } 209 }
203 r := &http.Request{ 210 r := &http.Request{
204 Body: newCombinedPsBody([]*buildbotBuild{b}, &ms , false), 211 Body: newCombinedPsBody([]*buildbotBuild{b}, &ms , false),
205 } 212 }
206 p := httprouter.Params{} 213 p := httprouter.Params{}
207 PubSubHandler(&router.Context{ 214 PubSubHandler(&router.Context{
208 Context: c, 215 Context: c,
209 Writer: h, 216 Writer: h,
210 Request: r, 217 Request: r,
211 Params: p, 218 Params: p,
212 }) 219 })
213 So(h.Code, ShouldEqual, 200) 220 So(h.Code, ShouldEqual, 200)
214 Convey("And stores correctly", func() { 221 Convey("And stores correctly", func() {
215 loadB := &buildbotBuild{ 222 loadB := &buildbotBuild{
216 Master: "Fake Master", 223 Master: "Fake Master",
217 Buildername: "Fake buildername", 224 Buildername: "Fake buildername",
218 Number: 1234, 225 Number: 1234,
219 } 226 }
220 err := ds.Get(c, loadB) 227 err := ds.Get(c, loadB)
221 So(err, ShouldBeNil) 228 So(err, ShouldBeNil)
222 So(loadB.Master, ShouldEqual, "Fake Master") 229 So(loadB.Master, ShouldEqual, "Fake Master")
223 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string") 230 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string")
224 » » » » m, t, err := getMasterJSON(c, "fakename") 231 » » » » m, t, err := getMasterJSON(c, "Fake Master")
225 So(err, ShouldBeNil) 232 So(err, ShouldBeNil)
226 So(t.Unix(), ShouldEqual, 981173106) 233 So(t.Unix(), ShouldEqual, 981173106)
227 » » » » So(m.Name, ShouldEqual, "fakename") 234 » » » » So(m.Name, ShouldEqual, "Fake Master")
228 So(m.Project.Title, ShouldEqual, "some title") 235 So(m.Project.Title, ShouldEqual, "some title")
229 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave") 236 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave")
230 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0) 237 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0)
231 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1) 238 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1)
232 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0], 239 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0],
233 ShouldEqual, 2222) 240 ShouldEqual, 2222)
234 }) 241 })
235 242
236 Convey("And a new master overwrites", func() { 243 Convey("And a new master overwrites", func() {
237 c, _ = testclock.UseTime(c, fakeTime.Add(time.Du ration(1*time.Second))) 244 c, _ = testclock.UseTime(c, fakeTime.Add(time.Du ration(1*time.Second)))
238 ms.Project.Title = "some other title" 245 ms.Project.Title = "some other title"
239 h = httptest.NewRecorder() 246 h = httptest.NewRecorder()
240 r := &http.Request{ 247 r := &http.Request{
241 Body: newCombinedPsBody([]*buildbotBuild {b}, &ms, false)} 248 Body: newCombinedPsBody([]*buildbotBuild {b}, &ms, false)}
242 p = httprouter.Params{} 249 p = httprouter.Params{}
243 PubSubHandler(&router.Context{ 250 PubSubHandler(&router.Context{
244 Context: c, 251 Context: c,
245 Writer: h, 252 Writer: h,
246 Request: r, 253 Request: r,
247 Params: p, 254 Params: p,
248 }) 255 })
249 So(h.Code, ShouldEqual, 200) 256 So(h.Code, ShouldEqual, 200)
250 » » » » m, t, err := getMasterJSON(c, "fakename") 257 » » » » m, t, err := getMasterJSON(c, "Fake Master")
251 So(err, ShouldBeNil) 258 So(err, ShouldBeNil)
252 So(m.Project.Title, ShouldEqual, "some other tit le") 259 So(m.Project.Title, ShouldEqual, "some other tit le")
253 So(t.Unix(), ShouldEqual, 981173107) 260 So(t.Unix(), ShouldEqual, 981173107)
254 » » » » So(m.Name, ShouldEqual, "fakename") 261 » » » » So(m.Name, ShouldEqual, "Fake Master")
255 }) 262 })
256 Convey("And a new build overwrites", func() { 263 Convey("And a new build overwrites", func() {
257 b.Times = buildbotTimesFinished(123.0, 124.0) 264 b.Times = buildbotTimesFinished(123.0, 124.0)
258 h = httptest.NewRecorder() 265 h = httptest.NewRecorder()
259 r = &http.Request{ 266 r = &http.Request{
260 Body: newCombinedPsBody([]*buildbotBuild {b}, &ms, false), 267 Body: newCombinedPsBody([]*buildbotBuild {b}, &ms, false),
261 } 268 }
262 p = httprouter.Params{} 269 p = httprouter.Params{}
263 PubSubHandler(&router.Context{ 270 PubSubHandler(&router.Context{
264 Context: c, 271 Context: c,
(...skipping 29 matching lines...) Expand all
294 Master: "Fake Master", 301 Master: "Fake Master",
295 Buildername: "Fake buildername", 302 Buildername: "Fake buildername",
296 Number: 1234, 303 Number: 1234,
297 } 304 }
298 err := ds.Get(c, loadB) 305 err := ds.Get(c, loadB)
299 So(err, ShouldBeNil) 306 So(err, ShouldBeNil)
300 So(*loadB.Times[0], ShouldEqual, 123.0) 307 So(*loadB.Times[0], ShouldEqual, 123.0)
301 So(*loadB.Times[1], ShouldEqual, 124.0) 308 So(*loadB.Times[1], ShouldEqual, 124.0)
302 }) 309 })
303 }) 310 })
311 Convey("Expire non-existant current build", func() {
312 b.Number = 1235
313 h = httptest.NewRecorder()
314 r = &http.Request{
315 Body: newCombinedPsBody([]*buildbotBuild {b}, &ms, false),
316 }
317 p = httprouter.Params{}
318 ds.GetTestable(c).Consistent(true)
hinoka 2016/10/12 06:58:31 This sort of cheats, because the pubsub handler st
319 PubSubHandler(&router.Context{
320 Context: c,
321 Writer: h,
322 Request: r,
323 Params: p,
324 })
325 So(h.Code, ShouldEqual, 200)
326 loadB := &buildbotBuild{
327 Master: "Fake Master",
328 Buildername: "Fake buildername",
329 Number: 1235,
330 }
331 err := ds.Get(c, loadB)
332 So(err, ShouldBeNil)
333 So(loadB.Finished, ShouldEqual, true)
334 So(*loadB.Times[0], ShouldEqual, 123.0)
335 So(loadB.Times[1], ShouldNotEqual, nil)
336 So(*loadB.Times[1], ShouldEqual, 555.0)
337 So(*loadB.Results, ShouldEqual, 2)
338 })
304 Convey("Large pubsub message", func() { 339 Convey("Large pubsub message", func() {
305 // This has to be a random string, so that after gzip compresses it 340 // This has to be a random string, so that after gzip compresses it
306 // it remains larger than 950KB 341 // it remains larger than 950KB
307 b.Text = append(b.Text, RandStringRunes(1500000) ) 342 b.Text = append(b.Text, RandStringRunes(1500000) )
308 h := httptest.NewRecorder() 343 h := httptest.NewRecorder()
309 r := &http.Request{ 344 r := &http.Request{
310 Body: newCombinedPsBody([]*buildbotBuild {b}, &ms, false), 345 Body: newCombinedPsBody([]*buildbotBuild {b}, &ms, false),
311 } 346 }
312 p := httprouter.Params{} 347 p := httprouter.Params{}
313 PubSubHandler(&router.Context{ 348 PubSubHandler(&router.Context{
(...skipping 30 matching lines...) Expand all
344 Runningbuilds: []*buildbotBuild{ 379 Runningbuilds: []*buildbotBuild{
345 { 380 {
346 Master: "Fake Master", 381 Master: "Fake Master",
347 Buildername: "Fake buildername", 382 Buildername: "Fake buildername",
348 Number: 2222, 383 Number: 2222,
349 Times: []*float64{&ft, nil }, 384 Times: []*float64{&ft, nil },
350 }, 385 },
351 }, 386 },
352 } 387 }
353 ms := buildbotMaster{ 388 ms := buildbotMaster{
354 » » » » Name: "fakename", 389 » » » » Name: "Fake Master",
355 Project: buildbotProject{Title: "some title"}, 390 Project: buildbotProject{Title: "some title"},
356 Slaves: slaves, 391 Slaves: slaves,
357 } 392 }
358 r := &http.Request{ 393 r := &http.Request{
359 Body: newCombinedPsBody([]*buildbotBuild{b}, &ms , true), 394 Body: newCombinedPsBody([]*buildbotBuild{b}, &ms , true),
360 } 395 }
361 p := httprouter.Params{} 396 p := httprouter.Params{}
362 PubSubHandler(&router.Context{ 397 PubSubHandler(&router.Context{
363 Context: c, 398 Context: c,
364 Writer: h, 399 Writer: h,
(...skipping 12 matching lines...) Expand all
377 loadB := &buildbotBuild{ 412 loadB := &buildbotBuild{
378 Master: "Fake Master", 413 Master: "Fake Master",
379 Buildername: "Fake buildername", 414 Buildername: "Fake buildername",
380 Number: 1234, 415 Number: 1234,
381 } 416 }
382 err = ds.Get(c, loadB) 417 err = ds.Get(c, loadB)
383 So(err, ShouldBeNil) 418 So(err, ShouldBeNil)
384 So(loadB.Master, ShouldEqual, "Fake Master") 419 So(loadB.Master, ShouldEqual, "Fake Master")
385 So(loadB.Internal, ShouldEqual, true) 420 So(loadB.Internal, ShouldEqual, true)
386 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string") 421 So(loadB.Currentstep.(string), ShouldEqual, "thi s is a string")
387 » » » » m, t, err := getMasterJSON(c, "fakename") 422 » » » » m, t, err := getMasterJSON(c, "Fake Master")
388 So(err, ShouldBeNil) 423 So(err, ShouldBeNil)
389 So(t.Unix(), ShouldEqual, 981173106) 424 So(t.Unix(), ShouldEqual, 981173106)
390 » » » » So(m.Name, ShouldEqual, "fakename") 425 » » » » So(m.Name, ShouldEqual, "Fake Master")
391 So(m.Project.Title, ShouldEqual, "some title") 426 So(m.Project.Title, ShouldEqual, "some title")
392 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave") 427 So(m.Slaves["testslave"].Name, ShouldEqual, "tes tslave")
393 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0) 428 So(len(m.Slaves["testslave"].Runningbuilds), Sho uldEqual, 0)
394 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1) 429 So(len(m.Slaves["testslave"].RunningbuildsMap), ShouldEqual, 1)
395 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0], 430 So(m.Slaves["testslave"].RunningbuildsMap["Fake buildername"][0],
396 ShouldEqual, 2222) 431 ShouldEqual, 2222)
397 }) 432 })
398 }) 433 })
399 }) 434 })
400 } 435 }
401 436
402 var secretProjectCfg = ` 437 var secretProjectCfg = `
403 ID: "buildbot-internal" 438 ID: "buildbot-internal"
404 Readers: "google.com" 439 Readers: "google.com"
405 ` 440 `
406 441
407 var aclConfgs = map[string]memcfg.ConfigSet{ 442 var aclConfgs = map[string]memcfg.ConfigSet{
408 "projects/buildbot-internal.git": { 443 "projects/buildbot-internal.git": {
409 "luci-milo.cfg": secretProjectCfg, 444 "luci-milo.cfg": secretProjectCfg,
410 }, 445 },
411 } 446 }
OLDNEW
« no previous file with comments | « milo/appengine/buildbot/pubsub.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698