Skip to content
This repository was archived by the owner on Apr 17, 2019. It is now read-only.

Commit af36cb9

Browse files
committed
add unit test for auto prioritize
1 parent 44489fa commit af36cb9

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

mungegithub/mungers/flake-manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func autoPrioritize(comments []libgithub.IssueComment, issueCreatedAt *time.Time
307307
weekCount := 0
308308

309309
for _, c := range comments {
310-
// TODO: think of a better way to identify flake comments
310+
// TODO: think of a better way to identify flake comments
311311
// "Failed:" is a special string contained in flake issue filed by flake-manager
312312
// Please make sure it matches the body generated by IssueSource.Body()
313313
if !sync.RobotUser.Has(*c.User.Login) || !strings.Contains(*c.Body, "Failed:") {
@@ -327,9 +327,9 @@ func autoPrioritize(comments []libgithub.IssueComment, issueCreatedAt *time.Time
327327

328328
// P2: By default
329329
// P1: Flake happens more than once in last month.
330-
// P0: Flake happens more than once in last week.
330+
// P0: Flake happens more than twice in last week.
331331
p := sync.PriorityP2
332-
if weekCount >= 2 {
332+
if weekCount >= 3 {
333333
p = sync.PriorityP0
334334
} else if monthCount >= 2 {
335335
p = sync.PriorityP1

mungegithub/mungers/flake-manager_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ import (
2020
"strings"
2121
"testing"
2222

23+
"github.com/google/go-github/github"
24+
github_testing "k8s.io/contrib/mungegithub/github/testing"
2325
cache "k8s.io/contrib/mungegithub/mungers/flakesync"
2426
"k8s.io/contrib/mungegithub/mungers/sync"
2527
"k8s.io/contrib/test-utils/utils"
28+
"time"
2629
)
2730

2831
func makeTestFlakeManager() *FlakeManager {
@@ -82,3 +85,70 @@ func TestBrokenJobSource(t *testing.T) {
8285
expect(t, source.Title(), "e2e-gce: broken test run")
8386
checkCommon(t, &source)
8487
}
88+
89+
func flakecomment(id int, createdAt time.Time) github.IssueComment {
90+
return github_testing.Comment(id, "k8s-bot", createdAt, "Failed:")
91+
}
92+
93+
func TestAutoPrioritize(t *testing.T) {
94+
testcases := []struct {
95+
comments []github.IssueComment
96+
issueCreatedAt time.Time
97+
expectPriority int
98+
}{
99+
// New flake issue
100+
{
101+
comments: []github.IssueComment{},
102+
issueCreatedAt: time.Now(),
103+
expectPriority: 2,
104+
},
105+
{
106+
comments: []github.IssueComment{
107+
flakecomment(1, time.Now()),
108+
},
109+
issueCreatedAt: time.Now().Add(-1 * 29 * 24 * time.Hour),
110+
expectPriority: 1,
111+
},
112+
{
113+
comments: []github.IssueComment{
114+
flakecomment(1, time.Now()),
115+
flakecomment(1, time.Now().Add(-1*3*24*time.Hour)),
116+
flakecomment(1, time.Now().Add(-1*6*24*time.Hour)),
117+
},
118+
issueCreatedAt: time.Now().Add(-1 * 30 * 24 * time.Hour),
119+
expectPriority: 0,
120+
},
121+
{
122+
comments: []github.IssueComment{
123+
flakecomment(1, time.Now()),
124+
flakecomment(1, time.Now().Add(-8*24*time.Hour)),
125+
},
126+
issueCreatedAt: time.Now().Add(-1 * 29 * 24 * time.Hour),
127+
expectPriority: 1,
128+
},
129+
{
130+
comments: []github.IssueComment{
131+
flakecomment(1, time.Now()),
132+
flakecomment(1, time.Now().Add(-8*24*time.Hour)),
133+
flakecomment(1, time.Now().Add(-15*24*time.Hour)),
134+
flakecomment(1, time.Now().Add(-20*24*time.Hour)),
135+
},
136+
issueCreatedAt: time.Now().Add(-1 * 29 * 24 * time.Hour),
137+
expectPriority: 1,
138+
},
139+
{
140+
comments: []github.IssueComment{
141+
flakecomment(1, time.Now()),
142+
flakecomment(1, time.Now().Add(-1*3*24*time.Hour)),
143+
},
144+
issueCreatedAt: time.Now().Add(-1 * 6 * 24 * time.Hour),
145+
expectPriority: 0,
146+
},
147+
}
148+
for _, tc := range testcases {
149+
p := autoPrioritize(tc.comments, &tc.issueCreatedAt)
150+
if p.Priority() != tc.expectPriority {
151+
t.Errorf("Expected priority: %d, But got: %d", tc.expectPriority, p.Priority())
152+
}
153+
}
154+
}

0 commit comments

Comments
 (0)