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

Side by Side Diff: go/src/infra/monitoring/analyzer/analyzer_test.go

Issue 1125263004: dispatcher: fix test result parsing, build ranges for failure alerts, other fixes (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: fixed typo in comments Created 5 years, 7 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package analyzer 5 package analyzer
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "infra/monitoring/messages" 9 "infra/monitoring/messages"
10 "reflect" 10 "reflect"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 name: "Future master", 94 name: "Future master",
95 url: "http://fake.master", 95 url: "http://fake.master",
96 be: messages.BuildExtract{ 96 be: messages.BuildExtract{
97 CreatedTimestamp: messages.EpochTime(110), 97 CreatedTimestamp: messages.EpochTime(110),
98 }, 98 },
99 t: time.Unix(100, 0), 99 t: time.Unix(100, 0),
100 want: []messages.Alert{}, 100 want: []messages.Alert{},
101 }, 101 },
102 } 102 }
103 103
104 » a := New(&mockClient{}, 10) 104 » a := New(&mockClient{}, 0, 10)
105 105
106 for _, test := range tests { 106 for _, test := range tests {
107 a.now = fakeNow(test.t) 107 a.now = fakeNow(test.t)
108 got := a.MasterAlerts(test.url, &test.be) 108 got := a.MasterAlerts(test.url, &test.be)
109 if !reflect.DeepEqual(got, test.want) { 109 if !reflect.DeepEqual(got, test.want) {
110 t.Errorf("%s failed. Got %+v, want: %+v", test.name, got , test.want) 110 t.Errorf("%s failed. Got %+v, want: %+v", test.name, got , test.want)
111 } 111 }
112 } 112 }
113 } 113 }
114 114
115 func TestBuilderAlerts(t *testing.T) { 115 func TestBuilderAlerts(t *testing.T) {
116 tests := []struct { 116 tests := []struct {
117 name string 117 name string
118 url string 118 url string
119 be messages.BuildExtract 119 be messages.BuildExtract
120 filter string 120 filter string
121 t time.Time 121 t time.Time
122 wantBuilders []messages.Alert 122 wantBuilders []messages.Alert
123 wantMasters []messages.Alert 123 wantMasters []messages.Alert
124 }{ 124 }{
125 { 125 {
126 name: "Empty", 126 name: "Empty",
127 url: "https://build.chromium.org/p/fake.master/ json",
127 wantBuilders: []messages.Alert{}, 128 wantBuilders: []messages.Alert{},
128 wantMasters: []messages.Alert{}, 129 wantMasters: []messages.Alert{},
129 }, 130 },
130 { 131 {
131 name: "No Alerts", 132 name: "No Alerts",
132 » » » url: "http://fake.master", 133 » » » url: "https://build.chromium.org/p/fake.master/json",
133 be: messages.BuildExtract{ 134 be: messages.BuildExtract{
134 CreatedTimestamp: messages.EpochTime(100), 135 CreatedTimestamp: messages.EpochTime(100),
135 }, 136 },
136 t: time.Unix(100, 0), 137 t: time.Unix(100, 0),
137 wantBuilders: []messages.Alert{}, 138 wantBuilders: []messages.Alert{},
138 wantMasters: []messages.Alert{}, 139 wantMasters: []messages.Alert{},
139 }, 140 },
140 } 141 }
141 142
142 » a := New(&mockClient{}, 10) 143 » a := New(&mockClient{}, 0, 10)
143 144
144 for _, test := range tests { 145 for _, test := range tests {
145 a.now = fakeNow(test.t) 146 a.now = fakeNow(test.t)
146 got := a.BuilderAlerts(test.url, &test.be) 147 got := a.BuilderAlerts(test.url, &test.be)
147 if !reflect.DeepEqual(got, test.wantBuilders) { 148 if !reflect.DeepEqual(got, test.wantBuilders) {
148 t.Errorf("%s failed. Got %+v, want: %+v", test.name, got , test.wantBuilders) 149 t.Errorf("%s failed. Got %+v, want: %+v", test.name, got , test.wantBuilders)
149 } 150 }
150 } 151 }
151 } 152 }
152 153
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 }, 207 },
207 b: messages.Builders{ 208 b: messages.Builders{
208 State: messages.StateBuilding, 209 State: messages.StateBuilding,
209 BuilderName: "fake.builder", 210 BuilderName: "fake.builder",
210 CachedBuilds: []int64{0, 1, 2, 3}, 211 CachedBuilds: []int64{0, 1, 2, 3},
211 CurrentBuilds: []int64{5, 6, 7, 8}, 212 CurrentBuilds: []int64{5, 6, 7, 8},
212 }, 213 },
213 time: time.Unix(0, 0).Add(4 * time.Hour), 214 time: time.Unix(0, 0).Add(4 * time.Hour),
214 wantAlerts: []messages.Alert{ 215 wantAlerts: []messages.Alert{
215 { 216 {
216 » » » » » Key: "fake.master.fake.builder.hung", 217 » » » » » Key: "fake.master.fake.builder.hung ",
217 » » » » » Title: "fake.master.fake.builder is hung in step fake_step.", 218 » » » » » Title: "fake.master.fake.builder is h ung in step fake_step.",
218 » » » » » Time: messages.TimeToEpochTime(time.Uni x(0, 0).Add(4 * time.Hour)), 219 » » » » » Time: messages.TimeToEpochTime(time. Unix(0, 0).Add(4 * time.Hour)),
219 » » » » » Body: "fake.master.fake.builder has bee n building for 3h59m50s (last step update 1970-01-01 00:00:10 +0000 UTC), past t he alerting threshold of 3h0m0s", 220 » » » » » Body: "fake.master.fake.builder has been building for 3h59m50s (last step update 1970-01-01 00:00:10 +0000 UTC), pas t the alerting threshold of 3h0m0s",
221 » » » » » Severity: 1,
220 Links: []messages.Link{ 222 Links: []messages.Link{
221 {Title: "Builder", Href: "https: //build.chromium.org/p/fake.master/builders/fake.builder"}, 223 {Title: "Builder", Href: "https: //build.chromium.org/p/fake.master/builders/fake.builder"},
222 {Title: "Last build", Href: "htt ps://build.chromium.org/p/fake.master/builders/fake.builder/builds/3"}, 224 {Title: "Last build", Href: "htt ps://build.chromium.org/p/fake.master/builders/fake.builder/builds/3"},
223 {Title: "Last build step", Href: "https://build.chromium.org/p/fake.master/builders/fake.builder/builds/3/steps/ fake_step"}, 225 {Title: "Last build step", Href: "https://build.chromium.org/p/fake.master/builders/fake.builder/builds/3/steps/ fake_step"},
224 }, 226 },
225 }, 227 },
226 }, 228 },
227 wantErrs: []error{}, 229 wantErrs: []error{},
228 }, 230 },
229 } 231 }
230 232
231 » a := New(nil, 10) 233 » a := New(nil, 0, 10)
232 234
233 for _, test := range tests { 235 for _, test := range tests {
234 a.now = fakeNow(test.time) 236 a.now = fakeNow(test.time)
235 a.Client = mockClient{ 237 a.Client = mockClient{
236 build: test.builds, 238 build: test.builds,
237 } 239 }
238 gotAlerts, gotErrs := a.builderAlerts(test.master, test.builder, &test.b) 240 gotAlerts, gotErrs := a.builderAlerts(test.master, test.builder, &test.b)
239 if !reflect.DeepEqual(gotAlerts, test.wantAlerts) { 241 if !reflect.DeepEqual(gotAlerts, test.wantAlerts) {
240 t.Errorf("%s failed. Got:\n%+v, want:\n%+v", test.name, gotAlerts, test.wantAlerts) 242 t.Errorf("%s failed. Got:\n%+v, want:\n%+v", test.name, gotAlerts, test.wantAlerts)
241 } 243 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 want: []string{}, 297 want: []string{},
296 }, 298 },
297 { 299 {
298 name: "GTests", 300 name: "GTests",
299 f: stepFailure{ 301 f: stepFailure{
300 step: messages.Steps{ 302 step: messages.Steps{
301 Name: "something_tests", 303 Name: "something_tests",
302 }, 304 },
303 }, 305 },
304 testResults: &messages.TestResults{ 306 testResults: &messages.TestResults{
305 » » » » Tests: map[string]messages.TestResult{ 307 » » » » Tests: map[string]interface{}{
306 » » » » » "test a": messages.TestResult{ 308 » » » » » "test a": map[string]interface{}{
307 » » » » » » Expected: "PASS", 309 » » » » » » "expected": "PASS",
308 » » » » » » Actual: "FAIL", 310 » » » » » » "actual": "FAIL",
309 }, 311 },
310 }, 312 },
311 }, 313 },
312 want: []string{"test a"}, 314 want: []string{"test a"},
313 }, 315 },
314 } 316 }
315 317
316 mc := &mockClient{} 318 mc := &mockClient{}
317 » a := New(mc, 10) 319 » a := New(mc, 0, 10)
318 320
319 for _, test := range tests { 321 for _, test := range tests {
320 mc.testResults = test.testResults 322 mc.testResults = test.testResults
321 got := a.reasonsForFailure(test.f) 323 got := a.reasonsForFailure(test.f)
322 if !reflect.DeepEqual(got, test.want) { 324 if !reflect.DeepEqual(got, test.want) {
323 t.Errorf("% s failed. Got: %+v, want: %+v", test.name, g ot, test.want) 325 t.Errorf("% s failed. Got: %+v, want: %+v", test.name, g ot, test.want)
324 } 326 }
325 } 327 }
326 } 328 }
327 329
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 Name: "broken_step", 385 Name: "broken_step",
384 IsFinished: true, 386 IsFinished: true,
385 Results: []interface{}{float6 4(3)}, 387 Results: []interface{}{float6 4(3)},
386 }, 388 },
387 }, 389 },
388 }, 390 },
389 }, 391 },
390 } 392 }
391 393
392 mc := &mockClient{} 394 mc := &mockClient{}
393 » a := New(mc, 10) 395 » a := New(mc, 0, 10)
394 396
395 for _, test := range tests { 397 for _, test := range tests {
396 mc.build = test.b 398 mc.build = test.b
397 a.bCache = test.bCache 399 a.bCache = test.bCache
398 got, err := a.stepFailures(test.master, test.builder, test.bID) 400 got, err := a.stepFailures(test.master, test.builder, test.bID)
399 if !reflect.DeepEqual(got, test.want) { 401 if !reflect.DeepEqual(got, test.want) {
400 t.Errorf("%s failed.\nGot:\n%+v\nwant:\n%+v", test.name, got, test.want) 402 t.Errorf("%s failed.\nGot:\n%+v\nwant:\n%+v", test.name, got, test.want)
401 } 403 }
402 if !reflect.DeepEqual(err, test.wantErr) { 404 if !reflect.DeepEqual(err, test.wantErr) {
403 t.Errorf("%s failed. Got %+v, want %+v", test.name, err, test.wantErr) 405 t.Errorf("%s failed. Got %+v, want %+v", test.name, err, test.wantErr)
404 } 406 }
405 } 407 }
406 } 408 }
407 409
410 func TestStepFailureAlerts(t *testing.T) {
411 tests := []struct {
412 name string
413 failures []stepFailure
414 testResults messages.TestResults
415 alerts []messages.Alert
416 err error
417 }{
418 {
419 name: "empty",
420 alerts: []messages.Alert{},
421 },
422 {
423 name: "single failure",
424 failures: []stepFailure{
425 {
426 masterName: "fake.master",
427 builderName: "fake.builder",
428 build: messages.Builds{
429 Number: 2,
430 },
431 step: messages.Steps{
432 Name: "steps",
433 },
434 },
435 {
436 masterName: "fake.master",
437 builderName: "fake.builder",
438 build: messages.Builds{
439 Number: 42,
440 },
441 step: messages.Steps{
442 Name: "fake_tests",
443 },
444 },
445 },
446 testResults: messages.TestResults{},
447 alerts: []messages.Alert{
448 {
449 Key: "fake.master.fake.builder.fake_te sts.",
450 Title: "Builder step failure: fake.maste r.fake.builder",
451 Type: "buildfailure",
452 Extension: messages.BuildFailure{
453 Builders: []messages.AlertedBuil der{
454 {
455 Name: " fake.builder",
456 URL: " https://build.chromium.org/p/fake.master/builders/fake.builder",
457 FirstFailure: 4 2,
458 LatestFailure: 4 2,
459 },
460 },
461 },
462 },
463 },
464 },
465 }
466
467 mc := &mockClient{}
468 a := New(mc, 0, 10)
469 a.now = fakeNow(time.Unix(0, 0))
470
471 for _, test := range tests {
472 mc.testResults = &test.testResults
473 alerts, err := a.stepFailureAlerts(test.failures)
474 if !reflect.DeepEqual(alerts, test.alerts) {
475 t.Errorf("%s failed. Got:\n\t%+v, want:\n\t%+v", test.na me, alerts, test.alerts)
476 }
477 if !reflect.DeepEqual(err, test.err) {
478 t.Errorf("%s failed. Got %+v, want %+v", test.name, err, test.err)
479 }
480 }
481 }
482
408 func TestLatestBuildStep(t *testing.T) { 483 func TestLatestBuildStep(t *testing.T) {
409 tests := []struct { 484 tests := []struct {
410 name string 485 name string
411 b messages.Builds 486 b messages.Builds
412 wantStep string 487 wantStep string
413 wantUpdate messages.EpochTime 488 wantUpdate messages.EpochTime
414 wantErr error 489 wantErr error
415 }{ 490 }{
416 { 491 {
417 name: "blank", 492 name: "blank",
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 messages.TimeToEpochTime (time.Unix(7, 0)), 592 messages.TimeToEpochTime (time.Unix(7, 0)),
518 }, 593 },
519 }, 594 },
520 }, 595 },
521 }, 596 },
522 wantStep: StepCompletedRun, 597 wantStep: StepCompletedRun,
523 wantUpdate: messages.TimeToEpochTime(time.Unix(42, 0)), 598 wantUpdate: messages.TimeToEpochTime(time.Unix(42, 0)),
524 }, 599 },
525 } 600 }
526 601
527 » a := New(&mockClient{}, 10) 602 » a := New(&mockClient{}, 0, 10)
528 a.now = fakeNow(time.Unix(0, 0)) 603 a.now = fakeNow(time.Unix(0, 0))
529 for _, test := range tests { 604 for _, test := range tests {
530 gotStep, gotUpdate, gotErr := a.latestBuildStep(&test.b) 605 gotStep, gotUpdate, gotErr := a.latestBuildStep(&test.b)
531 if gotStep != test.wantStep { 606 if gotStep != test.wantStep {
532 t.Errorf("%s failed. Got %q, want %q.", test.name, gotSt ep, test.wantStep) 607 t.Errorf("%s failed. Got %q, want %q.", test.name, gotSt ep, test.wantStep)
533 } 608 }
534 if gotUpdate != test.wantUpdate { 609 if gotUpdate != test.wantUpdate {
535 t.Errorf("%s failed. Got %v, want %v.", test.name, gotUp date, test.wantUpdate) 610 t.Errorf("%s failed. Got %v, want %v.", test.name, gotUp date, test.wantUpdate)
536 } 611 }
537 if gotErr != test.wantErr { 612 if gotErr != test.wantErr {
538 t.Errorf("%s failed. Got %s, want %s.", test.name, gotEr r, test.wantErr) 613 t.Errorf("%s failed. Got %s, want %s.", test.name, gotEr r, test.wantErr)
539 } 614 }
540 } 615 }
541 } 616 }
OLDNEW
« no previous file with comments | « go/src/infra/monitoring/analyzer/analyzer.go ('k') | go/src/infra/monitoring/analyzer/test_failures.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698