@@ -165,3 +165,77 @@ func TestPullCreate_EmptyChangesWithSameCommits(t *testing.T) {
165
165
assert .Contains (t , text , "This branch is already included in the target branch. There is nothing to merge." )
166
166
})
167
167
}
168
+ << << << < HEAD
169
+ == == == =
170
+
171
+ func TestPullStatusDelayCheck (t * testing.T ) {
172
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
173
+ defer test .MockVariableValue (& setting .Repository .PullRequest .DelayCheckForInactiveDays , 1 )()
174
+ defer test .MockVariableValue (& pull .AddPullRequestToCheckQueue )()
175
+
176
+ session := loginUser (t , "user2" )
177
+
178
+ run := func (t * testing.T , fn func (* testing.T )) (issue3 * issues.Issue , checkedPrID int64 ) {
179
+ pull .AddPullRequestToCheckQueue = func (prID int64 ) {
180
+ checkedPrID = prID
181
+ }
182
+ fn (t )
183
+ issue3 = unittest .AssertExistsAndLoadBean (t , & issues.Issue {RepoID : 1 , Index : 3 })
184
+ _ = issue3 .LoadPullRequest (t .Context ())
185
+ return issue3 , checkedPrID
186
+ }
187
+
188
+ assertReloadingInterval := func (t * testing.T , interval string ) {
189
+ req := NewRequest (t , "GET" , "/user2/repo1/pulls/3" )
190
+ resp := session .MakeRequest (t , req , http .StatusOK )
191
+ attr := "data-pull-merge-box-reloading-interval"
192
+ if interval == "" {
193
+ assert .NotContains (t , resp .Body .String (), attr )
194
+ } else {
195
+ assert .Contains (t , resp .Body .String (), fmt .Sprintf (`%s="%v"` , attr , interval ))
196
+ }
197
+ }
198
+
199
+ // PR issue3 is merageable at the beginning
200
+ issue3 , checkedPrID := run (t , func (t * testing.T ) {})
201
+ assert .Equal (t , issues .PullRequestStatusMergeable , issue3 .PullRequest .Status )
202
+ assert .Zero (t , checkedPrID )
203
+ assertReloadingInterval (t , "" ) // the PR is mergeable, so no need to reload the merge box
204
+
205
+ // setting.IsProd = false // it would cause data-race because the queue handlers might be running and reading its value
206
+ // assertReloadingInterval(t, "1") // make sure dev mode always do merge box reloading, to make sure the UI logic won't break
207
+ // setting.IsProd = true
208
+
209
+ // when base branch changes, PR status should be updated, but it is inactive for long time, so no real check
210
+ issue3 , checkedPrID = run (t , func (t * testing.T ) {
211
+ testEditFile (t , session , "user2" , "repo1" , "master" , "README.md" , "new content 1" )
212
+ })
213
+ assert .Equal (t , issues .PullRequestStatusChecking , issue3 .PullRequest .Status )
214
+ assert .Zero (t , checkedPrID )
215
+ assertReloadingInterval (t , "2000" ) // the PR status is "checking", so try to reload the merge box
216
+
217
+ // view a PR with status=checking, it starts the real check
218
+ issue3 , checkedPrID = run (t , func (t * testing.T ) {
219
+ req := NewRequest (t , "GET" , "/user2/repo1/pulls/3" )
220
+ session .MakeRequest (t , req , http .StatusOK )
221
+ })
222
+ assert .Equal (t , issues .PullRequestStatusChecking , issue3 .PullRequest .Status )
223
+ assert .Equal (t , issue3 .PullRequest .ID , checkedPrID )
224
+
225
+ // when base branch changes, still so no real check
226
+ issue3 , checkedPrID = run (t , func (t * testing.T ) {
227
+ testEditFile (t , session , "user2" , "repo1" , "master" , "README.md" , "new content 2" )
228
+ })
229
+ assert .Equal (t , issues .PullRequestStatusChecking , issue3 .PullRequest .Status )
230
+ assert .Zero (t , checkedPrID )
231
+
232
+ // then allow to check PRs without delay, when base branch changes, the PRs will be checked
233
+ setting .Repository .PullRequest .DelayCheckForInactiveDays = - 1
234
+ issue3 , checkedPrID = run (t , func (t * testing.T ) {
235
+ testEditFile (t , session , "user2" , "repo1" , "master" , "README.md" , "new content 3" )
236
+ })
237
+ assert .Equal (t , issues .PullRequestStatusChecking , issue3 .PullRequest .Status )
238
+ assert .Equal (t , issue3 .PullRequest .ID , checkedPrID )
239
+ })
240
+ }
241
+ >> >> >> > 44 ece1e6f3 (Explicitly not update indexes when sync database schemas (#34281 ))
0 commit comments