@@ -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
2831func 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