summaryrefslogtreecommitdiffstats
path: root/models/issue_test.go
diff options
context:
space:
mode:
authorGusted <williamzijl7@hotmail.com>2021-11-08 22:14:46 +0100
committerGitHub <noreply@github.com>2021-11-08 23:14:46 +0200
commita3f9e9234cbb099b821a6ea9c575927be18948de (patch)
tree24740136097ba5f4dfc39723bc6479d2c8dc5b54 /models/issue_test.go
parent640f0e1ddf7a5cae8a778e989046e7438067a56c (diff)
downloadgitea-a3f9e9234cbb099b821a6ea9c575927be18948de.tar.gz
gitea-a3f9e9234cbb099b821a6ea9c575927be18948de.zip
Fix stats upon searching issues (#17566)
* Fix stat chunks searching - Fixes a issue whereby the given chunk of issueIDs wasn't respected and thus the returned results where not the correct results. * Add tests Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/issue_test.go')
-rw-r--r--models/issue_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/models/issue_test.go b/models/issue_test.go
index 8894d80201..9df91aeb99 100644
--- a/models/issue_test.go
+++ b/models/issue_test.go
@@ -435,3 +435,43 @@ func TestResourceIndex(t *testing.T) {
}
wg.Wait()
}
+
+func TestCorrectIssueStats(t *testing.T) {
+ assert.NoError(t, db.PrepareTestDatabase())
+
+ // Because the condition is to have chunked database look-ups,
+ // We have to more issues than `maxQueryParameters`, we will insert.
+ // maxQueryParameters + 10 issues into the testDatabase.
+ // Each new issues will have a constant description "Bugs are nasty"
+ // Which will be used later on.
+
+ issueAmount := maxQueryParameters + 10
+
+ var wg sync.WaitGroup
+ for i := 0; i < issueAmount; i++ {
+ wg.Add(1)
+ go func(i int) {
+ testInsertIssue(t, fmt.Sprintf("Issue %d", i+1), "Bugs are nasty", 0)
+ wg.Done()
+ }(i)
+ }
+ wg.Wait()
+
+ // Now we will get all issueID's that match the "Bugs are nasty" query.
+ total, ids, err := SearchIssueIDsByKeyword("Bugs are nasty", []int64{1}, issueAmount, 0)
+
+ // Just to be sure.
+ assert.NoError(t, err)
+ assert.EqualValues(t, issueAmount, total)
+
+ // Now we will call the GetIssueStats with these IDs and if working,
+ // get the correct stats back.
+ issueStats, err := GetIssueStats(&IssueStatsOptions{
+ RepoID: 1,
+ IssueIDs: ids,
+ })
+
+ // Now check the values.
+ assert.NoError(t, err)
+ assert.EqualValues(t, issueStats.OpenCount, issueAmount)
+}